summaryrefslogtreecommitdiffstats
path: root/admin/survey/classes/class.SurveyTheme.php
blob: 9793b76a1abe006c96a8d39c2001b624e64e1de2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
<?php 

class SurveyTheme {
	
	private $sid = null;					# id ankete
	private $surveyInfo = null;				# podatki ankete

	public $current_skin = null;			# trenutni skin
	public $current_mobile_skin = null;		# trenutni mobilni skin
	private $current_group = null;			# grupa trenutnega skina
	private $groups = array();				# grupe z skini

	function __construct($sid=0, $themePreview = false) {
		global $site_path;
		global $site_domain;
		global $global_user_id;
		global $admin_type;
		global $debug;
		
		$this->sid = $sid;

		SurveyInfo::getInstance()->SurveyInit($sid);
		$this->surveyInfo = SurveyInfo::getInstance()->getSurveyRow();
		$this->current_skin = $this->surveyInfo['skin'];
		$this->current_mobile_skin = $this->surveyInfo['mobile_skin'];

		# polovimo grupe skinov
		# dodamo sistemsko
		$this->groups['0'] = array('name'=>'Sistemske teme');
		$this->groups['-1'] = array('name'=>'Lastne teme');
		$this->groups['-2'] = array('name'=>'Safe teme');
		$this->groups['-3'] = array('name'=>'Mobilne teme');
		
		$skinsArray = array();
		$skinsArrayPersonal = array();
		
		# polovimo vse skine v direktoriju
		$dir = opendir($site_path . 'main/survey/skins/');
		while ($file = readdir($dir)) {
			
			$ext = pathinfo($file, PATHINFO_EXTENSION);
			if ($ext == 'css' && $file[0] != '_' && $file[0] != '.') {
					
				// Lastne teme
				if (strpos($file, $global_user_id.'_') === true) {
					$this->groups[-1]['skins'][] = $file;
					
					if ($file == $this->current_skin.'.css')
						$this->current_group = -1;
				}
				// Ni uporabniska tema
				else {
					
					// Standardni skini
					$standard_skins = array(
						1 => '1kaBlue.css',
						2 => '1kaRed.css',
						3 => '1kaOrange.css', 
						4 => '1kaGreen.css', 
						5 => '1kaPurple.css', 
						6 => '1kaBlack.css',
						7 => '1kaOffice.css',
						8 => '1kaNature.css',
						9 => 'Otroci3.css',
						10 => 'Otroci4.css',
						11 => 'Embed.css', 
						12 => 'Embed2.css', 
						13 => 'Slideshow.css'
					);
					//if((($admin_type == '0' || $admin_type == '1') && (strpos($site_url, 'www.1ka.si') || strpos($site_url, 'test.1ka.si'))) || $debug == '1'){
						$standard_skins[14] = 'Uni.css';
						$standard_skins[15] = 'Fdv.css';
						$standard_skins[16] = 'Cdi.css';
						$standard_skins[17] = 'WebSM.css';
					//}
					
					// Novi safe skini so v loceni skupini
					$safe_skins = array(
						'Center.css', 
						'Center2.css', 
						'Oko.css', 
						'Oko2.css', 
						'Otroci.css', 
						'Otroci2.css', 
						'Safe.css', 
						'Safe2.css', 
						'Safe3.css'
					);
					
					// Mobile skini
					$mobile_skins = array(
						1 => 'MobileBlue.css', 
						2 => 'MobileRed.css', 
						3 => 'MobileOrange.css', 
						4 => 'MobileGreen.css', 
						5 => 'MobilePurple.css', 
						6 => 'MobileBlack.css'
					);
					//if((($admin_type == '0' || $admin_type == '1') && (strpos($site_url, 'www.1ka.si') || strpos($site_url, 'test.1ka.si'))) || $debug == '1'){
						$mobile_skins[7] = 'MobileUni.css';
						$mobile_skins[8] = 'MobileFdv.css';
						$mobile_skins[9] = 'MobileCdi.css';
					//}
					
					// Safe skini
					if(in_array($file, $safe_skins)){
						$this->groups[-2]['skins'][] = $file;
						
						if ($file == $this->current_skin.'.css')
							$this->current_group = -2;
					}					
					// Mobile skini
					elseif($key = array_search($file, $mobile_skins)){
						$this->groups[-3]['skins'][$key] = $file;
					}				
					// Navadni skini
					elseif($key = array_search($file, $standard_skins)){
						$this->groups[0]['skins'][$key] = $file;
						
						if ($file == $this->current_skin.'.css')
							$this->current_group = 0;
					}
				}
			}
		}
		
		// Sortiramo skine
		ksort($this->groups[0]['skins']);
		
		// Sortiramo safe skine - po abecedi
		sort($this->groups[-2]['skins']);
		
		// Sortiramo mobilne skine
		ksort($this->groups[-3]['skins']);
	}

	function getGroups () {
	
		return $this->groups;
	}
	
	function Ajax() {
		switch ($_GET['a']) {
			case 'changeGroup':
				$this->displayGroupThemes($_POST['gid']);
			break;
			case 'changeTheme':
				$this->changeTheme($_POST['css'],$_POST['gid']);
			break;
			case 'changeProgressbar':
				$this->changeProgressbar();
			break;
			case 'theme_rename':
				$this->themeRename($_POST['msg']);
			break;
			case 'theme_rename_confirm':
				$this->themeRenameConfirm();
			break;
			case 'theme_delete':
				$this->themeDelete();
			break;
			case 'add_theme':
				$this->ajax_add_theme();
			break;
            case 'checboxThemeSave':
                $this->ajaxSaveChecboxTheme($_POST['anketa'],$_POST['checkbox']);
            breake;
			
			default:
			print_r("<pre>");
			print_r($_POST);
			print_r($_GET);
			break;
		}
	}

	
	function displayGroup($groupId = null) {
		global $lang;
		
		if ($groupId == null)
			$groupId = 0;
		
		echo '<div class="themes-content">';
		
		echo '<div id="div_theme_groups">';
		$this->displayGroupSelector($groupId);
		echo '</div>';

		echo '<div id="div_theme_group_holder">';
		$this->displayGroupThemes($groupId);
		echo '</div>';

		// tole sem premaknil izven onload.js da se ne klice vedno po nepotrebnem
		?><script> themes_init(); </script><?
	
		echo '</div>';
	}
	
	function handleEditing() {
		global $lang;
		global $global_user_id;
		
		// preusmeritev, ko kliknemo na prilagodi pri sistemski temi in naredimo nov profil
		if ( isset($_GET['profile_new']) ) {
			
			if ($_GET['name'] != '')
				$name = $_GET['name'];
			else
				$name = $_GET['profile_new'].'';
			
			$sql = sisplet_query("INSERT INTO srv_theme_profiles (id, usr_id, skin, name) VALUES ('', '$global_user_id', '".$_GET['profile_new']."', '".$name."')");
			$profile = mysqli_insert_id($GLOBALS['connect_db']);
			
			$s = sisplet_query("UPDATE srv_anketa SET skin='".$_GET['profile_new']."', skin_profile='".$profile."' WHERE id = '".$this->sid."'");
			if (!$s) echo mysqli_error($GLOBALS['connect_db']);
			
			header("Location: index.php?anketa=".$this->sid."&a=theme-editor&profile=".$profile.'&newalert=1');
			die();
		}
		
		// preusmeritev, ko kliknemo na prilagodi pri sistemski MOBILNI temi in naredimo nov profil
		if ( isset($_GET['profile_new_mobile']) ) {
			
			if ($_GET['name'] != '')
				$name = $_GET['name'];
			else
				$name = $_GET['profile_new_mobile'].'';
			
			$sql = sisplet_query("INSERT INTO srv_theme_profiles_mobile (id, usr_id, skin, name) VALUES ('', '$global_user_id', '".$_GET['profile_new_mobile']."', '".$name."')");
			$profile = mysqli_insert_id($GLOBALS['connect_db']);
			
			$s = sisplet_query("UPDATE srv_anketa SET mobile_skin='".$_GET['profile_new_mobile']."', skin_profile_mobile='".$profile."' WHERE id = '".$this->sid."'");
			if (!$s) echo mysqli_error($GLOBALS['connect_db']);
			
			header("Location: index.php?anketa=".$this->sid."&a=theme-editor&profile=".$profile.'&newalert=1&mobile=1');
			die();
		}
		
		$row = SurveyInfo::getInstance()->getSurveyRow();
		
		// urejanje CSSa
		if ( $_GET['t'] == 'css' ) {
			
			// CSS za mobilen skin
			if($_GET['mobile'] == '1'){
				$sqlp = sisplet_query("SELECT usr_id, skin FROM srv_theme_profiles_mobile WHERE id = '".$_GET['profile']."'");
				$rowp = mysqli_fetch_array($sqlp);
				
				$skin = $rowp['skin'];
				
				// nastavljena je sistemska tema, moramo jo spremeniti v lastno
				if (strpos($skin, $rowp['usr_id'].'_') === false) {
					
					$skin_name = $rowp['usr_id'].'_'.$skin;
					$css_content = file_get_contents('../../main/survey/skins/'.$skin.'.css');				
					
					$name = $rowp['usr_id'].'_'.$skin;
					
					while ( file_exists('../../main/survey/skins/'.$name.'.css') ) {
						$name = $name.'1';
					}
					
					$f = fopen('../../main/survey/skins/'.$name.'.css', 'w');
					fwrite($f, $css_content);
					fclose($f);
					
					$skin = $name;
					
					sisplet_query("UPDATE srv_theme_profiles_mobile SET skin = '$skin' WHERE id = '".$_GET['profile']."'");
				}
			}
			else{
				$sqlp = sisplet_query("SELECT usr_id, skin FROM srv_theme_profiles WHERE id = '".$_GET['profile']."'");
				$rowp = mysqli_fetch_array($sqlp);
				
				$skin = $rowp['skin'];
				
				// nastavljena je sistemska tema, moramo jo spremeniti v lastno
				if (strpos($skin, $rowp['usr_id'].'_') === false) {
					
					$skin_name = $rowp['usr_id'].'_'.$skin;
					$css_content = file_get_contents('../../main/survey/skins/'.$skin.'.css');				
					
					$name = $rowp['usr_id'].'_'.$skin;
					
					while ( file_exists('../../main/survey/skins/'.$name.'.css') ) {
						$name = $name.'1';
					}
					
					$f = fopen('../../main/survey/skins/'.$name.'.css', 'w');
					fwrite($f, $css_content);
					fclose($f);
					//header("Location: index.php?anketa=".$this->sid."&a=edit_css&skin=".$name."&newalert=1");
					//die();
					
					$skin = $name;
					
					sisplet_query("UPDATE srv_theme_profiles SET skin = '$skin' WHERE id = '".$_GET['profile']."'");
				}
			}
			
			$_GET['skin'] = $skin;
		}
	}
	
	// urejanje teme
	function displayEditing () {
		global $lang;
		global $global_user_id;

		$mobile = (isset($_GET['mobile']) && $_GET['mobile'] == '1') ? '_mobile' : '';
		
		// najprej se pohendla ce gre za nove profile itd...
		$this->handleEditing();
		
		echo '<div class="themes-content">';
		
		$sql = sisplet_query("SELECT name FROM srv_theme_profiles".$mobile." WHERE id = '".$_GET['profile']."'");
		$row = mysqli_fetch_array($sql);
		
		echo '<h2>'.$lang['srv_themes_mod'].': <span class="red">'.$row['name'].'</span></h2>';
		//self::displayTabs();
		
		if ( !isset($_GET['t']) ) {
			
			$ste = new SurveyThemeEditor($this->sid);
			$ste->display();
		
		} elseif ( $_GET['t'] == 'css' ) {
			
			$this->edit_css();
			
		} elseif ( $_GET['t'] == 'upload' ) {
			
			$this->upload_css();
			
		}
		
		echo '</div>';
	}

		
	function displayGroupSelector ($groupId = null) {
		global $lang,$site_url;
		global $global_user_id;

		$row = SurveyInfo::getInstance()->getSurveyRow();
		
		$simple_name = $this->current_skin;
		
		if ($row['skin_profile'] == 0) {
			$skin_name = $this->strip_name($simple_name);
		} else {
			$sqla = sisplet_query("SELECT name FROM srv_theme_profiles WHERE id = '".$row['skin_profile']."'");
			$rowa = mysqli_fetch_array($sqla);
			$skin_name = $rowa['name'];
		}


		echo '<span class="theme_header">'.$lang['srv_current_theme'].': ';
		if($row['skin_profile'] == 0){
			echo '<a href="index.php?anketa=' . $this->sid . '&a=theme-editor&profile_new=' . $simple_name . '"><span class="bold" style="font-size:16px;">' . $skin_name . '</span>' . '</a>';
		}else {
			echo '<a href="index.php?anketa=' . $this->sid . '&a=theme-editor&profile=' . $row['skin_profile'] . '"><span class="bold" style="font-size:16px;">' . $skin_name . '</span>' . '</a>';
		}
		
		echo '</span><br /><br />';
	}
	
	function displayAdvancedSettings ($groupId) {
		global $lang,$site_url;
		global $site_path, $global_user_id;
		global $admin_type;
		
		$row = $this->surveyInfo;
		
		$simple_name = $this->current_skin;
		
		echo '<h2><a href="#" onclick="javascript:$(\'#show_more\').slideToggle(); return false;">'.$lang['srv_show_all_settings'].'</a></h2>';
		
		echo '<fieldset id="show_more" style="display:none; margin-bottom:40px">';
		
		echo '<br /><span class="bold">'.$lang['srv_offline_edit'].':</span>';
		echo '<form name="upload" enctype="multipart/form-data" action="upload.php?anketa=' . $this->sid . '" method="post" />';
		echo '<p><label for="skin">' . $lang['srv_uploadtheme'] . ':</label> ';
		echo '<input type="file" name="fajl" onchange="submit();" onmouseout="survey_upload();" />';
		echo ' (' . $lang['srv_skintmpl1'] . ' <a href="' . $site_url . 'main/survey/skins/'.$row['skin'].'.css" target="_blank">' . $lang['srv_skintmpl'] . '</a>)';
		echo '</p></form>';
		echo '<p style="font-size:90%; color: gray">'.$lang['srv_skin_disclamer'].'</p>';
		
		echo '<br /><span class="bold">'.$lang['srv_upload_pic'].':</span>';
		
		echo '<form name="upload" enctype="multipart/form-data" action="upload.php?anketa=' . $this->sid . '" method="post" />';
		echo '<p><label for="skin">' . $lang['srv_upload_pic2'] . ':</label> ';
		echo '<input type="file" name="fajl" onchange="submit();" onmouseout="survey_upload();" />';
		echo '</p></form>';
		echo '<p style="font-size:90%; color: gray">'.$lang['srv_upload_pic_disclaimer'].'</p><br />';
		
		// prikazemo uploadane slike
		$dir = opendir($site_path . 'main/survey/uploads/');
		$skinsArray = array();
		$skinsArrayPersonal = array();
		while ($file = readdir($dir)) {
			
			if ( $file!='.' && $file!='..') {
				$allowed = false;
				
				if (is_numeric( substr($file, 0, strpos($file, '_')) )) {
					$owner = (int)substr($file, 0, strpos($file, '_')); 
					if ($owner == $global_user_id)
						$allowed = true;
				}
				
				if ($allowed) {
					echo '<a href="'.$site_url.'main/survey/uploads/'.$file.'" target="_blank"><img src="'.$site_url.'main/survey/uploads/'.$file.'" alt="" style="max-width:200px; max-height:200px"></a> ';
				}
			}
		}
		echo '</fieldset>';
	}

    function ajaxSaveChecboxTheme($idAnkete, $value){
        sisplet_query("UPDATE srv_anketa SET skin_checkbox='$value' WHERE id='$idAnkete'");
    }


	function displayGroupThemes ($groupId) {
		global $lang;
		global $site_domain;
		
		// Custom skini
		$this->displayThemes(-1);
		
		// Ostali default skini
		$this->displayThemes($groupId);
		
		// Mobilni skini
		$this->displayThemes(-3);
		
		// Safe skini - samo na domeni safe.si in test.1ka.si (za testiranje)
		if(strpos($site_domain, "safe.si") || $site_domain == "test.1ka.si"){
			$this->displayThemes(-2);
		}
	}
	
	function displayThemes ($groupId) {
		global $lang, $site_url;
		global $global_user_id;
 
		//if (count($this->groups[$groupId]['skins'])>0 || $groupId == -1) {
			
		$rowa = SurveyInfo::getSurveyRow();
		
		if($groupId == -2)
			echo '<h2>'.$lang['srv_safe_themes'].'</h2>';
		elseif ($groupId == -3)
			echo '<h2>'.$lang['srv_mobile_themes'].'</h2>';
		elseif ($groupId != -1)
			echo '<h2>'.$lang['srv_system_themes'].'</h2>';
		else{
			echo '<h2>'.$lang['srv_user_themes'].' ';
			echo '<span class="user_themes_button faicon plus icon-blue pointer" style="margin-bottom:6px;" onClick="toggle_custom_themes(); return false;"> </span>';
			echo '</h2>';
		}

		echo '<div id="div_theme_group" '.($groupId==-1 ? ' class="custom" style="display:none;"' : '').'>';
		
		$sqlg = sisplet_query("SELECT id FROM srv_grupa WHERE ank_id='$this->sid' ORDER BY vrstni_red ASC LIMIT 1");
		$rowg = mysqli_fetch_array($sqlg);
		$grupa = $rowg['id'];
		
		$profiles = 0;


		// Profili lastnih tem
		if ($groupId == -1) {
					
			// preverimo se, ce trenutno izbran skin pripada drugemu userju (v tem primeru ga vseeno prikazemo)
			$is_current = false;
			if ( isset($this->groups[$groupId]['skins']) && count($this->groups[$groupId]['skins']) > 0 ) {
				foreach ($this->groups[$groupId]['skins'] AS $skinid => $skin) {
					$simple_name = preg_replace("/\.css$/", '', $skin);
					$is_current = ($this->current_skin == $simple_name && $rowa['skin_profile'] == 0) ? true : false;
				}
			}
			$sql = sisplet_query("SELECT id FROM srv_theme_profiles WHERE usr_id = '$global_user_id' ORDER BY name ASC");
			while ($row = mysqli_fetch_array($sql)) {
				$is_current = ($rowa['skin_profile'] == $row['id']) ? true : false;
			}
			if (!$is_current) {
				$append_skin = " OR id = '".$rowa['skin_profile']."' ";
			} else {
				$append_skin = "";
			}
				
			// Custom navadni skini
			$sql = sisplet_query("SELECT id, name, skin FROM srv_theme_profiles WHERE usr_id = '$global_user_id' $append_skin ORDER BY name ASC");
			while ($row = mysqli_fetch_array($sql)) {
				
				$skin = $row['skin'];
				$src = ''.SurveyInfo::getSurveyLink().'&grupa='.$grupa.'&no_preview=1&preview=on&theme_profile='.$row['id'].'';
				$is_current_skin = ($rowa['skin_profile'] == $row['id']) ? true : false;
								
				echo '<div class="custom_theme_holder '.($is_current_skin ? ' active' : '').'">';
				
				// Title
				echo '<span class="custom_theme_title" gid="'.$groupId.'" css="'.urlencode($skin).'" alt="'.$row['name'].'" title="'.$lang['srv_changetheme'].'" onclick="te_change_profile(\''.$row['id'].'\', true); return false;" alt="'.$row['name'].'">'.substr($row['name'], 0, 30).(strlen($row['name']) > 30 ? '...' : '').'</span>';
			
				// Preview theme
				echo ' <a href="#" class="theme_links_preview" src="'.$src.'"><span class="custom_theme_preview"><span class="faicon preview"></span>'.$lang['srv_poglejanketo2'].'</span></a>';

				// Delete theme
				if ($groupId == -1) 
					echo ' <a href="#" onclick="if (confirm(\''.$lang['srv_ask_delete'].'\')) te_delete_profile(\''.$row['id'].'\', false); return false;" class="theme_delete" css="'.urlencode($skin).'"><span class="custom_theme_delete"><span class="faicon delete_circle icon-orange"></span> '.$lang['srv_anketadelete_txt'].'</span></a>';
					
				// Edit theme
				echo ' <a href="index.php?anketa='.$this->sid.'&a=theme-editor&profile='.$row['id'].'"><span class="custom_theme_edit"><span class="faicon palette"></span> '.$lang['edit3'].'</span></a>';	
			
				echo '</div>';
				
				$profiles++;
			}
			
			// Custom mobile skini
			$sql = sisplet_query("SELECT id, name, skin FROM srv_theme_profiles_mobile WHERE usr_id = '$global_user_id' ORDER BY name ASC");
			while ($row = mysqli_fetch_array($sql)) {
				
				$skin = $row['skin'];
				$src = ''.SurveyInfo::getSurveyLink().'&grupa='.$grupa.'&no_preview=1&preview=on&theme_profile='.$row['id'].'&mobile=1';
				$is_current_skin = ($rowa['skin_profile_mobile'] == $row['id']) ? true : false;
								
				echo '<div class="custom_theme_holder '.($is_current_skin ? ' active' : '').'">';
				
				// Title
				echo '<span class="custom_theme_title" gid="'.$groupId.'" css="'.urlencode($skin).'" alt="'.$row['name'].'" title="'.$lang['srv_changetheme'].'" onclick="te_change_profile(\''.$row['id'].'\', true, true); return false;" alt="'.$row['name'].'">'.substr($row['name'], 0, 30).(strlen($row['name']) > 30 ? '...' : '').' <span class="italic">('.$lang['srv_mobile_theme'].')</span></span>';
			
				// Preview theme
				echo ' <a href="#" class="theme_links_preview" src="'.$src.'"><span class="custom_theme_preview"><span class="faicon preview"></span>'.$lang['srv_poglejanketo2'].'</span></a>';

				// Delete theme
				if ($groupId == -1) 
					echo ' <a href="#" onclick="if (confirm(\''.$lang['srv_ask_delete'].'\')) te_delete_profile(\''.$row['id'].'\', true); return false;" class="theme_delete" css="'.urlencode($skin).'"><span class="custom_theme_delete"><span class="faicon delete_circle icon-orange"></span> '.$lang['srv_anketadelete_txt'].'</span></a>';
					
				// Edit theme
				echo ' <a href="index.php?anketa='.$this->sid.'&a=theme-editor&profile='.$row['id'].'&mobile=1"><span class="custom_theme_edit"><span class="faicon palette"></span> '.$lang['edit3'].'</span></a>';	
			
				echo '</div>';
				
				$profiles++;
			}
			
			if(mysqli_num_rows($sql) > 0)
				echo '<br />';
		}
		
		if ( isset($this->groups[$groupId]['skins']) && count($this->groups[$groupId]['skins']) > 0 ) {
			
			foreach ($this->groups[$groupId]['skins'] AS $skinid => $skin) {
				$simple_name = preg_replace("/\.css$/", '', $skin);
				$is_current_skin = ($this->current_skin == $simple_name && $rowa['skin_profile'] == 0) ? true : false;
				$is_current_mobile_skin = ($this->current_mobile_skin == $simple_name && $rowa['skin_profile_mobile'] == 0) ? true : false;
				
				$src = ''.SurveyInfo::getSurveyLink().'&grupa='.$grupa.'&no_preview=1&preview=on&theme='.$skin.'';
				if(substr($skin, 0, 6) == 'Mobile')
					$src .= '&mobile=1';

				echo '<div class="theme_label '.($is_current_skin || $is_current_mobile_skin ? 'span_theme_current' : '').'">';
				
				echo '<div class="theme_label_content">';
				
				// Preview slika
				if ($groupId == -1) echo '<a href="#" class="theme_delete theme" gid="'.$groupId.'" css="'.urlencode($skin).'">'.$lang['srv_anketadelete_txt'].'</a>';
				//echo '<span class="theme_links_rename as_link" theme="'.urlencode($skin).'">Preimenuj</span>';
				if ($groupId == -1)
					echo '<img src="'.$site_url.'public/img/skins_previews/'.($groupId==-1?'usertheme':urlencode($simple_name)).'.png" onclick="te_change_profile_oldskin(\''.$simple_name.'\', true); return false;" gid="'.$groupId.'" css="'.urlencode($skin).'" alt="'.$simple_name.'" title="'.$lang['srv_changetheme'].'">';
				else
					echo '<img src="'.$site_url.'public/img/skins_previews/'.urlencode($simple_name).'.png" class="theme" gid="'.$groupId.'" css="'.urlencode($skin).'" alt="'.$simple_name.'" title="'.$lang['srv_changetheme'].'">';
				
				// Ime teme
				echo '<span class="theme_name">';			
				echo $this->strip_name($simple_name.($simple_name=='1kaBlue' || $simple_name=='MobileBlue' ? ' ('.$lang['default'].')' : ''));
				// Vprasajcki
				if($simple_name == 'Embed' || $simple_name == 'Embed2' || $simple_name == 'Fdv' || $simple_name == 'Uni' || $simple_name == 'Slideshow')
					echo ' '.Help :: display('srv_skins_'.$simple_name);
				if($groupId == -1)
					echo ' (CSS)';					
				echo '</span>';
				
				echo '</div>';
					
				if($is_current_skin)
					echo ' <a href="index.php?anketa='.$this->sid.'&a=theme-editor&profile_new='.$rowa['skin'].'"><span class="faicon palette"></span> '.$lang['srv_te_theme_edit'].'</a>';
				
				if($is_current_mobile_skin)
					echo ' <a href="index.php?anketa='.$this->sid.'&a=theme-editor&profile_new_mobile='.$rowa['mobile_skin'].'"><span class="faicon palette"></span> '.$lang['srv_te_theme_edit'].'</a>';
	
				echo '<a href="#" class="theme_links_preview" src="'.$src.'"><span class="faicon preview"></span> '.$lang['srv_poglejanketo2'].'</a>';
				
				echo '</div>';
			}		
		} 
		elseif ($profiles == 0) {
			echo '<p>'.$lang['srv_te_no_profiles'].'</p>';
			echo '<br />';
		}
						
		echo '</div>';
	}
	
	function changeTheme($css, $gid) {
		global $site_path;
		 
		$_theme = urldecode($_POST['css']);
		
		$dir = $site_path . 'main/survey/skins/';

		if (file_exists($dir.$_theme)) {
			$_theme = preg_replace("/\.css$/", '', $_theme);
			
			// Mobilna anketa
			if($gid == -3){
				$strUpdate = "UPDATE srv_anketa SET mobile_skin = '$_theme', skin_profile_mobile='0' WHERE id=".$this->sid;
				$updated = sisplet_query($strUpdate);
				sisplet_query("COMMIT");
				
				SurveyInfo::getInstance()->resetSurveyData();
				
				$this->current_mobile_skin = $_theme;				
			}		
			else{
				// Nastavimo se mobilni skin glede na osnovnega
				$mobile_skin_update = '';
				if(in_array($_theme, array('1kaBlue', '1kaRed', '1kaOrange', '1kaGreen', '1kaPurple', '1kaBlack'))){
					$mobile_skin = str_replace('1ka', 'Mobile', $_theme);
					$mobile_skin_update = ", mobile_skin='".$mobile_skin."', skin_profile_mobile='0'";
				}
				elseif(in_array($_theme, array('Uni', 'Fdv', 'Cdi'))){
					$mobile_skin = 'Mobile'.$_theme;
					$mobile_skin_update = ", mobile_skin='".$mobile_skin."', skin_profile_mobile='0'";
				}
				
				$strUpdate = "UPDATE srv_anketa SET skin = '$_theme', skin_profile='0' ".$mobile_skin_update." WHERE id=".$this->sid;
				$updated = sisplet_query($strUpdate);
				sisplet_query("COMMIT");
				
				SurveyInfo::getInstance()->resetSurveyData();
				
				$this->current_skin = $_theme;
				
				// Popravimo se mobile skin ce smo ga slucajno preklopili
				if($mobile_skin_update != '')
					$this->current_mobile_skin = $mobile_skin;
			}
		}	
		
		ob_start();
		$this->displayGroupThemes(0);
		$data['group_themes'] = ob_get_clean();
		ob_start();
		$this->displayGroupSelector();
		$data['theme_name'] = ob_get_clean();
		
		echo json_encode($data);
	}

	function changeProgressbar() {
		$progressbar = $_POST['progressbar'];
		$strUpdate = "UPDATE srv_anketa SET progressbar = '$progressbar' WHERE id=".$this->sid;
		$updated = sisplet_query($strUpdate);
		sisplet_query("COMMIT");
		SurveyInfo :: getInstance()->resetSurveyData();
	}
	
	function themeRename($msg = array()) {
		global $lang, $global_user_id;
		echo '<div id="div_theme_fullscreen">';
		echo '<div class="div_theme_fullscreen_content">';
		print_r("<PRE>");
		print_r($msg);
		print_r($_POST);
		print_r("</PRE>");
		$_theme_new = (isset($_POST['theme_new_name']) ? $_POST['theme_new_name'] : $_POST['theme']);
		$_theme_new = urldecode(preg_replace("/\.css$/", '', $_theme_new));
		# Če gre za lastno temo odstranimo $global_user_id+_
		if (is_numeric( substr($_theme_new, 0, strpos($_theme_new, '_')) )) {
			$owner = (int)substr($_theme_new, 0, strpos($_theme_new, '_')); 
			if ($owner == $global_user_id) {
				# odstranimo $global_user_id_ 
				$_theme_new = preg_replace("/^".$global_user_id."_/", '', $_theme_new);
			}
		}
		
		echo '<input id="theme" name="theme" type="hidden" value="'.$_POST['theme'].'">';
		echo '<label>Novo ime:</label><input id="theme_new_name" name="theme_new_name" type="text" value="'.$_theme_new.'">';
		echo '</div>'; 	#inv_FS_content
		echo '<div class="div_theme_fullscreen_btm">';
		echo '<span id="theme_rename_confirm" class="floatRight spaceRight buttonwrapper" ><a class="ovalbutton ovalbutton_orange" href="#" ><span>'.$lang['srv_rename_profile_yes'].'</span></a></span>';
		echo '<span id="theme_rename_cancle" class="floatRight spaceRight buttonwrapper" ><a class="ovalbutton ovalbutton_silver" href="#" ><span>'.$lang['srv_cancel'].'</span></a></span>';
		echo '<div class="clr" />';
		echo '</div>';
		
		echo '</div>';	
	}
	
	function themeRenameConfirm() {
		global $lang, $global_user_id, $site_path;
		$dir = $site_path . 'main/survey/skins/';
		$return = array('msg'=>'', 'error'=>'1', 'theme'=>$_POST['theme'], 'theme_new_name'=>$_POST['theme_new_name']);
		$_theme_old = urldecode($_POST['theme']);

		$_theme_new = preg_replace("/\.css$/", '', urldecode($_POST['theme_new_name']));

		# preverimo ali gre za lastno temo, na začetku dodamo $global_user_id+_
		if (is_numeric( substr($_theme_old, 0, strpos($_theme_old, '_')) )) {
			$owner = (int)substr($_theme_old, 0, strpos($_theme_old, '_')); 
			if ($owner == $global_user_id) {
				# gre za lastno temo, na začetku preventivno odstranimo $global_user_id_ in ga nato dodamo
				$_theme_new = $global_user_id.'_'.preg_replace("/^".$global_user_id."_/", '', $_theme_new);
			}
		}
		
		# novo ime ne sme biti prazno
		if (trim($_theme_new) == '' || $_theme_new == null) {
			$return['error'] = 1;			
			$return['msg'] = 'Ime teme ne sme biti prazno!';
			echo json_encode($return);
			exit;
		}
		$_theme_new = $_theme_new.'.css';		
		# preverimo obstoj stare datoteke
		if (!file_exists($dir.$_theme_old)) {
			$return['error'] = 2;			
			$return['msg'] = 'Izvorna datoteka ne obstaja!';
			echo json_encode($return);
			exit;
		}
		
		#preverimo ali je novo ime enako staremu
		if ($_theme_old == $_theme_new) {
			$return['error'] = 3;			
			$return['msg'] = 'Novo ime je enako staremu!';
			echo json_encode($return);
			exit;
		}
		
		# preverimo in preprečimo obstoj datoteke z novim imenom
		if (file_exists($dir.$_theme_new)) {
			$return['error'] = 4;			
			$return['msg'] = 'Datoteka s tem imenom že obstaja!';
			echo json_encode($return);
			exit;
		}

		#preimenujemo datoteko
		if ((int)rename($dir.$_theme_old,$dir.$_theme_new) == true) {
			#datoteka je bila uspešno preimenovana, popravimo še v bazi, če je potrebno
			$simple_name = preg_replace("/\.css$/", '', $_theme_new);
			$strUpdate = "UPDATE srv_anketa SET skin = '".$simple_name."' WHERE id=".$this->sid;
			$updated = sisplet_query($strUpdate);
			sisplet_query("COMMIT");
			$return = array('msg'=>(int)$updated, 'error'=>'0', 'theme'=>urlencode($_theme_new), 'theme_new_name'=>$_theme_new);
			echo json_encode($return);
			exit;
		} else {
			$return['error'] = 5;			
			$return['msg'] = 'Pri preimenovanju je prišlo do napake!';
			echo json_encode($return);
			exit;
		}
		
		# vse je ok!
		echo json_encode($return);
		exit;
		
 	}
	
	// izbrise temo
	function themeDelete() {
		global $site_path;
		global $global_user_id;
		
		$dir = $site_path . 'main/survey/skins/';
		$skin = urldecode( $_POST['css'] );

		// preverimo, da ima na zacetku user ID, da ne bo brisal kar vsega po vrsti XX_ ter .css na koncu
		if ( substr($skin, 0, strpos($skin, '_')+1 ) == $global_user_id.'_' && substr($skin, -4) == '.css' ) {
			
			unlink($dir.$skin);
		
		}	
		
		$sql = sisplet_query("SELECT skin FROM srv_anketa WHERE id = '{$_POST['anketa']}'");
		$row = mysqli_fetch_array($sql);

		if ($row['skin'] == substr($skin, 0, -4)) {
			sisplet_query("UPDATE srv_anketa SET skin='Default' WHERE id = '{$_POST['anketa']}'");
		}
	}
	
	// iz imena skina odstrani uid stevilko userja in _
	function strip_name ($simple_name) {
		
		// Popravimo se default skine - vstavimo presledek da lepse izgleda
		$skins = array(
			'1kaBlue (Privzeto)', '1kaRed', '1kaOrange', '1kaGreen', '1kaPurple', '1kaBlack', '1kaOffice', '1kaNature',
			'MobileBlue (Privzeto)', 'MobileRed', 'MobileOrange', 'MobileGreen', 'MobilePurple', 'MobileBlack',
			'MobileUni', 'MobileFdv', 'MobileCdi'
		);
		if(in_array($simple_name, $skins)){
			$simple_name = preg_replace('/(?<!\ )[A-Z]/', ' $0', $simple_name);
		}
		
		if ( is_numeric( substr($simple_name, 0, strpos($simple_name, '_')) ) )
			$simple_name = substr($simple_name, strpos($simple_name, '_')+1);
			
		return $simple_name;
	}
	
	function upload_css() {
		global $lang;
		global $site_url;
		
		$row = SurveyInfo::getSurveyRow();
	
		$default = 'Default';
		$skin = ($row['skin'] == '') ? $default : $row['skin'];
		
		echo '<br /><span class="bold">'.$lang['srv_add_theme_upload'].'</span>';
		echo '<form name="upload" enctype="multipart/form-data" action="upload.php?anketa=' . $this->sid . '&profile='.$_GET['profile'].'" method="post">';
		echo '<p><label for="skin">' . $lang['srv_uploadtheme'] . ':</label> ';
		echo '<input type="file" name="fajl" onchange="submit();">';
		echo ' (' . $lang['srv_skintmpl1'] . ' <a href="' . $site_url . 'main/survey/skins/'.$skin.'.css" target="_blank">' . $lang['srv_skintmpl'] . '</a>)';
		echo '</p></form>';
		
		
		echo '<p style="font-size:90%; color: gray">'.$lang['srv_skin_disclamer'].'</p>';
		
		echo '<a href="#" onclick="$(\'#vrednost_edit\').hide().html(\'\'); return false;" style="position:absolute; right:10px; bottom:10px">'.$lang['srv_zapri'].'</a>';
		
	}
	
	function edit_css () {
		global $lang;
		global $site_url;
		global $site_path;
		global $admin_type;
		global $global_user_id;
				
		$row = SurveyInfo::getInstance()->getSurveyRow();
		
		$skin = $_GET['skin'];

		echo '<div id="theme-editor">';
		
		echo '<div id="theme-editor-warning">'.$lang['srv_themes_edit_warning'].'</div>';
		
		echo '<form name="editcss" action="ajax.php?anketa='.$this->sid.'&a=save_editcss" method="post" onsubmit="return false;">';
		
		$profile = $_GET['profile'];
		$mobile = (isset($_GET['mobile']) && $_GET['mobile'] == '1') ? true : false;

		$sqlp = sisplet_query("SELECT usr_id FROM srv_theme_profiles".($mobile ? '_mobile' : '')." WHERE id = '$profile'");
		$rowp = mysqli_fetch_array($sqlp);
		
		$skin_name = str_replace($rowp['usr_id'].'_', '', $skin);
		
		//echo '<p>'.$lang['srv_skinname'].': <input type="text" name="skin_name" value="'.$skin_name.'" /></p>';
		echo '<input type="hidden" name="skin_name" value="'.$skin_name.'">';
		echo '<input type="hidden" name="profile" value="'.$_GET['profile'].'">';
		echo '<input type="hidden" name="mobile" value="'.($mobile ? '1' : '0').'">';
		
		echo '<br />';
		
		echo '<span class="bold">'.$lang['srv_themes_edit'].'</span>';
		echo '<p><textarea name="css_content" style="width:100%; height: 400px">';
		
		readfile('../../main/survey/skins/'.$skin.'.css');
		
		echo '</textarea></p>';
				
		echo '<p>';
				
		echo '<p><div class="buttonwrapper"><a class="ovalbutton ovalbutton_orange btn_savesettings floatLeft spaceRight" href="#" onclick="'; 
			?>$.post('ajax.php?anketa=<?=$this->sid?>&a=save_editcss', $('form[name=editcss]').serialize(), function (data) { 
				//if ( $('input[name=skin_name]').val() != $('input[name=old_name]').val() ) {
				//	window.location.href = 'index.php?anketa=<?=$this->sid?>&a=edit_css&skin='+data;
				//} else {
					var iframe = document.getElementById('theme-preview-iframe');
					iframe.src = iframe.src;
					if ( $('input[name=current_skin]').is(':checked') ) $('input[name=current_skin]').attr('disabled', true); 
				//}
			}); return false;<?php
		echo '"><span>'. $lang['edit1337'] . '</span></a>';
		
		//echo '<a class="ovalbutton ovalbutton_gray spaceRight floatLeft" href="index.php?anketa='.$this->sid.'&a=tema"><span>'.$lang['srv_theme_save_as_new'].'</span></a>';
		
		echo '<a class="ovalbutton ovalbutton_gray floatLeft" href="index.php?anketa='.$this->sid.'&a=tema"><span>'.$lang['back'].'</span></a></p>';
		echo '<div class="clr"></div>';
		echo '</div></p>';
		echo '</form>';
		
		echo '<br /><p><a href="#" onclick="javascript:$(\'#show_more\').slideToggle(); return false;">'.$lang['srv_upload_pic'].'</a></p>';
		
		echo '<fieldset id="show_more" style="'.($_GET['pic']=='open'?'':'display:none;').' margin-bottom:40px">';

		
		echo '<br /><span class="bold">'.$lang['srv_upload_pic'].':</span>';
		/*echo '<form name="upload" enctype="multipart/form-data" action="upload.php?anketa=' . $this->sid . '&logo=1" method="post" />';
		echo '<p><label for="skin">' . $lang['srv_upload_logo'] . ':</label> ';
		echo '<input type="file" name="fajl" onchange="submit();" onmouseout="survey_upload();" />';
		echo '</p></form>';		*/
		
		echo '<form name="upload" enctype="multipart/form-data" action="upload.php?anketa=' . $this->sid . '&skin='.$skin.'&profile='.$_GET['profile'].'" method="post" />';
		echo '<p><label for="skin">' . $lang['srv_upload_pic2'] . ':</label> ';
		echo '<input type="file" name="fajl" onchange="submit();" onmouseout="survey_upload();" />';
		echo '</p></form>';
		echo '<p style="font-size:90%; color: gray">'.$lang['srv_upload_pic_disclaimer'].'</p><br />';
		
		// prikazemo uploadane slike
		$dir = opendir($site_path . 'main/survey/uploads/');
		$skinsArray = array();
		$skinsArrayPersonal = array();
		while ($file = readdir($dir)) {
			
			if ( $file!='.' && $file!='..') {
				$allowed = false;
				
				if (is_numeric( substr($file, 0, strpos($file, '_')) )) {
					$owner = (int)substr($file, 0, strpos($file, '_')); 
					if ($owner == $global_user_id)
						$allowed = true;
				}
				
				if ($allowed) {
					echo '<a href="'.$site_url.'main/survey/uploads/'.$file.'" target="_blank"><img src="'.$site_url.'main/survey/uploads/'.$file.'" alt="" style="max-width:200px; max-height:200px"></a> ';
				}
			}
		}
		echo '</fieldset>';
		
		echo '<div id="success_save"></div>';
		
		echo '</div>';
		
		$sql = sisplet_query("SELECT id FROM srv_grupa WHERE ank_id='$this->sid' ORDER BY vrstni_red ASC LIMIT 1");
		$row = mysqli_fetch_array($sql);
		$grupa = $row['id'];
		
		//echo '<div id="theme-preview"><iframe id="theme-preview-iframe" src="'.SurveyInfo::getSurveyLink().'&grupa='.$grupa.'&no_preview=1&preview=on&theme='.$skin.'"></iframe></div>';
		echo '<div id="theme-preview"><iframe id="theme-preview-iframe" src="'.SurveyInfo::getSurveyLink().'&grupa='.$grupa.'&no_preview=1&preview=on&theme_profile='.$_GET['profile'].'&theme-preview=1'.($mobile ? '&mobile=1' : '').'"></iframe><div class="theme-overflow"></div></div>';		

		//echo '</div>';
		
		//echo '<div class="clr"></div>';
		
		//echo '</div>';
		
		SurveyThemeEditor::new_theme_alert($skin_name, true);
	}
	
	function ajax_add_theme () {
		global $lang;
		global $site_url;
		
		$row = SurveyInfo::getSurveyRow();
	
		$default = 'Default';
	
		echo '<h3 style="color:#900">'.$lang['srv_add_theme_css'].'</h3>';
		
		echo '<p>'.$lang['srv_select_base_theme'].': <select name="new_theme" id="new_theme" onchange="$(\'input[name=name]\').val( $(this).val() );">';
		foreach ($this->groups[0]['skins'] AS $key => $val) {
			$skin = str_replace('.css', '', $val);
			echo '<option value="'.$skin.'" '.($skin==$default?'selected':'').'>'.$skin.'</option>';
		}
		echo '</select> <span style="font-size:90%; color: gray">'.$lang['srv_select_base_theme_2'].'</span></p>';
		echo '<p>'.$lang['srv_skinname'].': <input type="text" name="name" value="'.$default.'"></p>';
		
		echo '<p><input type="submit" value="'.$lang['add'].'" onclick="window.location.href=\'index.php?anketa='.$this->sid.'&a=edit_css&new=1&skin=\'+$(\'#new_theme\').val()+\'&name=\'+$(\'input[name=name]\').val(); return false;"></p>';
	
		echo '<br /><h3 style="color:#900">'.$lang['srv_add_theme_upload'].'</h3>';
		echo '<form name="upload" enctype="multipart/form-data" action="upload.php?anketa=' . $this->sid . '" method="post">';
		echo '<p><label for="skin">' . $lang['srv_uploadtheme'] . ':</label> ';
		echo '<input type="file" name="fajl" onchange="submit();">';
		echo ' (' . $lang['srv_skintmpl1'] . ' <a href="' . $site_url . 'main/survey/skins/'.$row['skin'].'.css" target="_blank">' . $lang['srv_skintmpl'] . '</a>)';
		echo '</p></form>';
		
		
		echo '<p style="font-size:90%; color: gray">'.$lang['srv_skin_disclamer'].'</p>';
		
		echo '<a href="#" onclick="$(\'#vrednost_edit\').hide().html(\'\'); return false;" style="position:absolute; right:10px; bottom:10px">'.$lang['srv_zapri'].'</a>';
	}
	
}

?>