summaryrefslogtreecommitdiffstats
path: root/admin/survey/classes/class.RecodeValues.php
blob: eef65b0fdd393e2cbca193816acec7e332e5bada (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
<?php

class RecodeValues {
	private static $anketa = null;					# trenutna anketa
	private static $spremenljivka = null;			# trenutna spremenljivka
	private static $db_table = '';					# aktivnost
	private static $sprInfo = null;					# podatki o trenutni spremenljivki
	private static $cacheSpremenljivka = null;		# zakeširani podatki spremenljivke
	private static $smv = null;						# manjkajoe vrednosti ankete
	private static $options = null;					# možne izbire manjkajočih vrednosti
	private static $variables = null;				# Variable vprašanja
	private static $_operators = array(				# operatorji
							'0'=>'==',				# ==
							'1'=>'&ne;',	        # ≠
							'2'=>'&lt;',			# <
							'3'=>'&gt;',			# >
							'4'=>'&lt;=',			# <=
							'5'=>'&gt;=',			# >=
							'6'=>'interval'			# interval
							);	

	/**
	 * konstruktor
	 *
	 * @param mixed $anketa
	 */
	
	function __construct ($anketa = 0, $spremenljivka = 0) {
		if ((int)$anketa > 0 && (int)$spremenljivka > 0) {
			self::$anketa = $anketa;
			self::$spremenljivka = $spremenljivka;

			SurveyInfo::getInstance()->SurveyInit($anketa);
			if (SurveyInfo::getInstance()->getSurveyColumn('db_table') == 1)
				self::$db_table = '_active';
			
			# polovimo manjkajoče privzete vrednosti ankete
			self::$smv = new SurveyMissingValues(self::$anketa); 
			self::$smv -> Init();
			
			self::$cacheSpremenljivka = Cache::srv_spremenljivka(self::$spremenljivka);
		}
	}
	
	public static function DisplayMissingValuesForQuestion($displayForm=true) {
		global $lang;
		
		echo '<form name="spremenljivka_recode" method="post">';
		echo '<div id="recodeToNewSpr">';
		self::displayRecodeType();
		echo '</div>';
		echo '</form>';
	}

	
	/** Naloži manjkajoče vrednosti za spremenljivko
	 * 
	 * 
	 * Enter description here ...
	 */
	private static function LoadSpremenljivkaMissingValues($spremenljivka=null) {
		global $lang;
		if ($spremenljivka == null) {
			$spremenljivka = self::$spremenljivka;
		}
		
		$cacheSpremenljivka = Cache::srv_spremenljivka($spremenljivka);
		
		self::$options = array();
		self::$variables = array();
		if ((int)$spremenljivka > 0) {
			self::$options['_0_'] = array('naslov'=>$lang['srv_recode_type0'], 'variable'=>null, 'type'=>0);
			switch ($cacheSpremenljivka['tip']) {
				case 1:		# radio
				case 3:		# select
					$sql1 = sisplet_query("SELECT id, naslov, variable FROM srv_vrednost WHERE spr_id = '".$spremenljivka."' ORDER BY vrstni_red ASC");
					if (!$sql1) echo mysqli_error($GLOBALS['connect_db']);
					if (mysqli_num_rows($sql1)) {
						
						while ($row1 = mysqli_fetch_assoc($sql1)) {
							self::$variables[$row1['id']] = array('naslov'=>$row1['naslov'], 'variable'=>$row1['variable']);
							self::$options[$row1['id']] = array('naslov'=>$row1['naslov'], 'variable'=>$row1['variable'], 'type'=>0);
						}
					}
				break;
				case 17:	# razvrščanje
					$sql1 = sisplet_query("SELECT id, naslov, vrstni_red FROM srv_vrednost WHERE spr_id = '".$spremenljivka."' ORDER BY vrstni_red ASC");
					if (!$sql1) echo mysqli_error($GLOBALS['connect_db']);
					if (mysqli_num_rows($sql1)) {
						while ($row1 = mysqli_fetch_assoc($sql1)) {
							self::$variables[$row1['id']] = array('naslov'=>$row1['naslov'], 'variable'=>$row1['vrstni_red']);
							self::$options[$row1['id']] = array('naslov'=>$row1['naslov'], 'variable'=>$row1['vrstni_red'], 'type'=>0);
						}
					}
				break;
				case 2:		# checkbox
					self::$variables['1'] = array('naslov'=>'izbran', 'variable'=>'1');
					self::$variables['0'] = array('naslov'=>'neizbran', 'variable'=>'0');
					self::$options['1'] = array('naslov'=>'izbran', 'variable'=>'1', 'type'=>0);
					self::$options['0'] = array('naslov'=>'neizbran', 'variable'=>'0', 'type'=>0);
				break;
				case 6:		# multiradio
				case 19:	# multitext
				case 20:	# multinumber
					$sql1 = sisplet_query("SELECT naslov, variable FROM srv_grid WHERE spr_id='".$spremenljivka."' ORDER BY vrstni_red ASC");
					if (!$sql1) echo mysqli_error($GLOBALS['connect_db']);
					if (mysqli_num_rows($sql1)) {
						while ($row1 = mysqli_fetch_assoc($sql1)) {
							self::$variables[$row1['variable']] = array('naslov'=>$row1['naslov'], 'variable'=>$row1['variable']);
							self::$options[$row1['variable']] = array('naslov'=>$row1['naslov'], 'variable'=>$row1['variable']);
						}
					}
				break;
				case 16:	# multicheckbox
					self::$variables['0'] = array('naslov'=>'izbran', 'variable'=>'0');
					self::$variables['1'] = array('naslov'=>'neizbran', 'variable'=>'1');
					self::$options['0'] = array('naslov'=>'izbran', 'variable'=>'0', 'type'=>0);
					self::$options['1'] = array('naslov'=>'neizbran', 'variable'=>'1', 'type'=>0);
				break;
			}
		}
		# dodamo manjkajoče vrednosti če še niso
		# preberemo možne manjkajoče vrednosti
		$smvs = self::$smv-> GetSystemFlterByType(array(1));
		# zgeneriramo matriko izbranih manjkajočih vrednosti za anketo (anketne oz. sistemske mv)
		self::$options['_1_'] = array('naslov'=>$lang['srv_recode_type1'], 'variable'=>null, 'type'=>0);
		if (count($smvs)> 0) {
			foreach ($smvs AS $key => $value) {
				self::$options[$key] = array('naslov'=>$value, 'variable'=>$key, 'type'=>1);
			} 
		}
		$smvs = self::$smv-> GetSystemFlterByType(array(2,3));
		# zgeneriramo matriko izbranih manjkajočih vrednosti za anketo (anketne oz. sistemske mv)
		self::$options['_2_'] = array('naslov'=>$lang['srv_recode_type2'], 'variable'=>null, 'type'=>0);
		if (count($smvs)> 0) {
			foreach ($smvs AS $key => $value) {
				self::$options[$key] = array('naslov'=>$value, 'variable'=>$key, 'type'=>2);
			} 
		}
	}
	
	private static function show_new_mv_div() {
		echo '<div id="vprasanje_recode_new">';
		self::show_new_mv();
		echo '</div>';
	}
	
	private static function show_new_mv() {
		global $lang;
		
		echo 'Izberi vrednost:';
		echo '<input id="new_mv_value" type="text" size="5" autocomplete="off">';
		
		echo '<br/>';
		echo self::$spremenljivka;
		echo '<br/>';
		
		echo '<span class="buttonwrapper spaceRight floatRight">';
        echo '<a class="ovalbutton ovalbutton_orange" href="/" onclick="new_mv_add(\''.self::$spremenljivka.'\'); return false;"><span>'.$lang['add'].'</span></a>';
        echo '</span>';
		
		echo '<span class="buttonwrapper spaceRight floatRight">';
        echo '<a class="ovalbutton ovalbutton_gray" href="/" onclick="show_new_mv_cancel(); return false;"><span>'.$lang['srv_cancel'].'</span></a>';
        echo '</span>';        
	}
	
	private static function new_mv_add() {
		echo 'Napaka!!!';
		self::show_new_mv();
	}
	
	public static function Ajax() {
		switch ($_GET['a']) {
			case 'show_new_mv':
				self::show_new_mv_div();
			break;
			case 'new_mv_add':
				#self::new_mv_add();
			break;
			case 'refresh_mv':
				self::DisplayMissingValuesForQuestion();
			break;

			case 'add_new_numeric':
				self::AddNewNumericRecode();
			break;
			case 'changeRecodeType':
				self::changeRecodeType();
			break;
			default:
#				print_r($_POST);
#				print_r($_GET);
			break;
		}
	}
	
	public function removeRecodeForQuestion() {
		if ((int)self::$anketa > 0 && (int)self::$spremenljivka > 0) {
			# odstranimo rekodiranje za spremenljivko
			$sql = sisplet_query("DELETE FROM srv_recode WHERE ank_id = '".self::$anketa."' AND spr_id = '".self::$spremenljivka."'");
			if (!$sql) echo mysqli_error($GLOBALS['connect_db']);
			
			# preverimo ali imamo rekodiranje v novo spremenljivko, če ja, kasneje ponudimo tud izbris psremenljivke
			$qry = sisplet_query("SELECT to_spr_id FROM srv_recode_spremenljivka WHERE ank_id = '".self::$anketa."' AND spr_id = '".self::$spremenljivka."'");
			list($spr_id) = mysqli_fetch_row($qry);
			# pobrišemo še zapise v srv_recode_vrednost in srv_recode spremenljika
			$sql = sisplet_query("DELETE FROM srv_recode_spremenljivka WHERE ank_id = '".self::$anketa."' AND spr_id = '".self::$spremenljivka."'");
			if (!$sql) echo mysqli_error($GLOBALS['connect_db']);

			$sql = sisplet_query("DELETE FROM srv_recode_vrednost WHERE ank_id = '".self::$anketa."' AND spr1 = '".self::$spremenljivka."'");
			if (!$sql) echo mysqli_error($GLOBALS['connect_db']);
			
			sisplet_query("COMMIT");
			return (int)$spr_id;
		} else {
			return 0; 
		}
	}
	
	public function SetUpMissingValuesForQuestion() {
		if ((int)self::$anketa > 0 ) {
			# pobrišemo rekodirane vrednosti za morebitno rekodiranje v novo spremenljivko
			if (isset($_REQUEST['recodeToSpr']) && (int)$_REQUEST['recodeToSpr'] > 0) {
				$sql = sisplet_query("DELETE FROM srv_recode_vrednost WHERE ank_id = '".self::$anketa."' AND spr2 = '".(int)$_REQUEST['recodeToSpr']."'");
				if (!$sql) echo mysqli_error($GLOBALS['connect_db']);
			}
		
		
			# če imamo spremembe je potrebno na novo zgenerirati datoteko
			$strSelect = "SELECT search, value, operator FROM srv_recode WHERE ank_id = '".self::$anketa."' AND spr_id = '".self::$spremenljivka."' ORDER BY vrstni_red";
			$sqlSelect = sisplet_query($strSelect);
			$rowsBefore = array();
			$rowsAfter = array();
			while (list($search, $value, $operator) = mysqli_fetch_row($sqlSelect)) {
				$rowsBefore[] = $search."_".$value."_".(int)$operator;
			}
			
			# pobrišemo vse obstoječe zamenjave
			$sql = sisplet_query("DELETE FROM srv_recode WHERE ank_id = '".self::$anketa."' AND spr_id = '".self::$spremenljivka."'");
			if (!$sql) echo mysqli_error($GLOBALS['connect_db']);
			
			#rekodiramo kategorije
			if ( isset($_REQUEST['edit_recode_mv']) ) {
				# dodamo potrebne zamenjave za 
				$_for_replace = "";
				foreach ($_REQUEST as $key => $value) {
					$_tmp_value = substr($key, 5);
					if (substr($key, 0, 5) == 'MVFQ_' && $_tmp_value != $value) {
						if ($_for_replace != "") { $_for_replace .= ","; }
						$_for_replace .= " ('".self::$anketa."', '".self::$spremenljivka."', '$_tmp_value', '$value') ";
					}
				}
				
				
				# če moramo uporabiti zamenjave: 			
				if ($_for_replace != "") {
					$insertString = 'INSERT INTO srv_recode (ank_id, spr_id, search, value) VALUES '.$_for_replace;
					$sql1 = sisplet_query($insertString);
				}
			} else if( isset($_REQUEST['edit_recode_number']) ){
				# rekodiramo numerične
				$recoded = array();
				if (isset($_REQUEST['recode_number_operator'])) {
					foreach ($_REQUEST['recode_number_operator'] as $key => $value) {
						$recoded[$key]['operator'] = $value;
					}	
				}
				if (isset($_REQUEST['recode_number_search'])) {
					foreach ($_REQUEST['recode_number_search'] as $key => $value) {
						$recoded[$key]['search'] = trim($value);
					}	
				}
				if (isset($_REQUEST['recode_number_search1'])) {
					foreach ($_REQUEST['recode_number_search1'] as $key => $value) {
						$recoded[$key]['search1'] = trim($value);
					}	
				}
				if (isset($_REQUEST['recode_number_search2'])) {
					foreach ($_REQUEST['recode_number_search2'] as $key => $value) {
						$recoded[$key]['search2'] = trim($value);
					}	
				}
				if (isset($_REQUEST['recode_number_value'])) {
					foreach ($_REQUEST['recode_number_value'] as $key => $value) {
						$recoded[$key]['value'] = trim($value);
					}	
				}
				# pripravimo query
				if (count($recoded) > 0) {
					$_for_replace = "";
					$already_set = array();
					$vrstni_red = 1;
					foreach ($recoded AS $rKey => $recode) {
						$opreand = (int)$recode['operator'];
						if ( $opreand != 6) {
							$_search = $recode['search'];
						} else {
							$_search = $recode['search1'].','.$recode['search2'];
						}  
						if ( $_search != '' && $recode['value'] != ''
							#preprečimo zamenjavo iste vrednosti z istim operatorejm. 
							&& !( isset($already_set[$_search.'_'.$recode['operator']] ))
						) {
							if ($_for_replace != "") { 
								$_for_replace .= ","; 
							}
							
							$_for_replace .= " ('".self::$anketa."', '".self::$spremenljivka."', '$vrstni_red', '$_search', '".trim($recode['value'])."', '".(int)trim($recode['operator'])."') ";
							
							$already_set[$_search.'_'.$recode['operator']] = true;
						}
						$vrstni_red ++;
					}
					if ($_for_replace != "") {
						# izvedemo insert query
						$insertString = 'INSERT INTO srv_recode (ank_id, spr_id, vrstni_red, search, value, operator) VALUES '.$_for_replace;
						$sql1 = sisplet_query($insertString);
						if (!$sql1) {
							print_r(mysqli_error($GLOBALS['connect_db']));
						}
					}
				}
			
			}
			sisplet_query("COMMIT");
			
			# če imamo spremembe je potrebno na novo zgenerirati datoteko
			$strSelect = "SELECT search, value, operator FROM srv_recode WHERE ank_id = '".self::$anketa."' AND spr_id = '".self::$spremenljivka."' ORDER BY vrstni_red";
			$sqlSelect = sisplet_query($strSelect);
			while (list($search, $value, $operator) = mysqli_fetch_row($sqlSelect)) {
				$rowsAfter[] = $search."_".$value."_".(int)$operator;
			}			
			if ( (count( array_diff($rowsBefore, $rowsAfter) ) +  count( array_diff($rowsAfter, $rowsBefore) ) ) > 0) {
				# array-a nista enaka, imamo spremembe
				# pobrišimo datoteko, da se podatki zgenerirajo na novo
				global $site_path;
				$data_file_name = $site_path.'admin/survey/SurveyData/export_data_'.self::$anketa.'.dat';
				if (file_exists($data_file_name)) {
					unlink($data_file_name);
				}
				return true;
				
			}
			return false;
		}
		return false;
	}
	
	
	public function SetRecodeNumberNewVrednost() {
		if ((int)self::$anketa > 0 && (int)$_REQUEST['recode_type']== 1 && (int)$_REQUEST['edit_recode_number'] == 1) {

			# pobrišemo rekodirane vrednosti za morebitno rekodiranje v novo spremenljivko
			if ((int)self::$spremenljivka > 0) {
				$sql = sisplet_query("DELETE FROM srv_recode_vrednost WHERE ank_id = '".self::$anketa."' AND spr1 = '".(int)self::$spremenljivka."'");
				if (!$sql) echo mysqli_error($GLOBALS['connect_db']);
			}
	
			# pobrišemo vse mmorebitne obstoječe zamenjave za normalni number
			$sql = sisplet_query("DELETE FROM srv_recode WHERE ank_id = '".self::$anketa."' AND spr_id = '".self::$spremenljivka."'");
			if (!$sql) echo mysqli_error($GLOBALS['connect_db']);
					
			# pobrišemo vse morebitne obstoječe zamenjave za number
			$sql = sisplet_query("DELETE FROM srv_recode_number WHERE ank_id = '".self::$anketa."' AND spr_id = '".self::$spremenljivka."'");
			if (!$sql) echo mysqli_error($GLOBALS['connect_db']);
					
			if( isset($_REQUEST['recode_number_vrednost']) ){
				# rekodiramo numerične
				$recoded = array();
				if (isset($_REQUEST['recode_number_operator'])) {
					foreach ($_REQUEST['recode_number_operator'] as $key => $value) {
						$recoded[$key]['operator'] = $value;
					}
				}
				if (isset($_REQUEST['recode_number_search'])) {
					foreach ($_REQUEST['recode_number_search'] as $key => $value) {
						$recoded[$key]['search'] = trim($value);
					}
				}
				if (isset($_REQUEST['recode_number_search1'])) {
					foreach ($_REQUEST['recode_number_search1'] as $key => $value) {
						$recoded[$key]['search1'] = trim($value);
					}
				}
				if (isset($_REQUEST['recode_number_search2'])) {
					foreach ($_REQUEST['recode_number_search2'] as $key => $value) {
						$recoded[$key]['search2'] = trim($value);
					}
				}
				if (isset($_REQUEST['recode_number_vrednost'])) {
					foreach ($_REQUEST['recode_number_vrednost'] as $key => $value) {
						$recoded[$key]['value'] = trim($value);
					}
				}
				# pripravimo query
				if (count($recoded) > 0) {
					$_for_replace = "";
					$already_set = array();
					$vrstni_red = 1;
					foreach ($recoded AS $rKey => $recode) {
						$opreand = (int)$recode['operator'];
						if ( $opreand != 6) {
							$_search = $recode['search'];
						} else {
							$_search = $recode['search1'].','.$recode['search2'];
						}
						if ( $_search != '' && $recode['value'] != ''
								#preprečimo zamenjavo iste vrednosti z istim operatorejm.
								&& !( isset($already_set[$_search.'_'.$recode['operator']] ))
						) {
							if ($_for_replace != "") {
								$_for_replace .= ",";
							}
	
							$_for_replace .= " ('".self::$anketa."', '".self::$spremenljivka."', '$vrstni_red', '$_search', '".trim($recode['value'])."', '".(int)trim($recode['operator'])."') ";
	
							$already_set[$_search.'_'.$recode['operator']] = true;
						}
						$vrstni_red ++;
					}
					if ($_for_replace != "") {
						# izvedemo insert query
						$insertString = 'INSERT INTO srv_recode_number (ank_id, spr_id, vrstni_red, search, vred_id, operator) VALUES '.$_for_replace;
						$sql1 = sisplet_query($insertString);
						if (!$sql1) {
							print_r(mysqli_error($GLOBALS['connect_db']));
						}
					}
				}
	
			}
			sisplet_query("COMMIT");
		}
		return false;
	}
	
	public function AddNewNumericRecode() {
		global $lang;
		
		$recode_type = (int)$_POST['recode_type'];
		
		self::LoadSpremenljivkaMissingValues();
		
		if ( $recode_type == 0) {
			echo '<li>';
			echo '<span class="faicon move_updown moveY"></span>';
			printf($lang['srv_recode_number_if'],self::$cacheSpremenljivka['variable']);
			echo '&nbsp;<select name="recode_number_operator[]" onChange="recode_operator_changed(this);">';
			foreach (self::$_operators AS $value => $operator) {
				$selected = ($value == '0') ? ' selected="selected"' : ''; 
				echo '<option value="'.$value.'"'.$selected.'>'.$operator.'</option>';
			}
			echo '</select>';
			#echo '&nbsp;<input type="text" name="recode_number_search[]" value="0" size="5" autocomplete="off"/>';
			
			echo '<span class="recode_int_first">';
			echo '&nbsp;<input type="text" name="recode_number_search[]" value="0" size="12" autocomplete="off"/>';
			echo '</span>';
			echo '<span class="recode_int_seccond hidden">';
			echo '&nbsp;[<input type="text" name="recode_number_search1[]" value="0" size="5" autocomplete="off"/>,';
			echo '<input type="text" name="recode_number_search2[]" value="1" size="5" autocomplete="off"/>]';
			echo '</span>';
			
			echo '&nbsp;'.$lang['srv_recode_number_to'];
							
			echo '<select name="recode_number_type[]" onChange="recode_number_type_changed(this);">';
			foreach (self::$options AS $oKey => $option) {
				if ($option['variable'] == null && $oKey != '_0_') {
					echo '<option disabled="disabled">'.$option['naslov'].'</option>';
					$_value = null;								
				} else {
					$_value = ($oKey == '_0_') ? '_' : $option['variable'];
					$_selected = ($oKey == '_0_') ? 'selected="selected"' : '';
					$_label = ($oKey == '_0_') ? $option['naslov'] : '&nbsp;&nbsp;'.$option['naslov'].' ['.$option['variable'].']'; 
					echo '<option value="'.$_value.'" '.$_selected.'>'.$_label.'</option>';
				}
			}
			echo '</select>';
			
			echo '&nbsp;<input type="text" name="recode_number_value[]" value="0" size="5" autocomplete="off"/>';
			echo '&nbsp;<span class="floatRight spaceRight faicon delete_circle icon-orange_link" onclick="recode_delete_numeric(\''.self::$spremenljivka.'\',this);"></span>';
			echo '</li>';
		} else {
			# polovimo osnovne lastnosti rekodiranja
			$selectString = "SELECT to_spr_id FROM srv_recode_spremenljivka WHERE ank_id='".self::$anketa."' AND spr_id='".self::$spremenljivka."'";
			$sqlSelect = sisplet_query($selectString);
			if (!$sqlSelect) echo mysqli_error($GLOBALS['connect_db']);
			list($to_spr_id) = mysqli_fetch_row($sqlSelect);
			
			self::LoadSpremenljivkaMissingValues($to_spr_id);
			$new_spr_vrednosti = self::$options;
			self::LoadSpremenljivkaMissingValues(self::$spremenljivka);
				

			echo '<li>';
			echo '<span class="faicon move_updown moveY"></span>';
			printf($lang['srv_recode_number_if'],self::$cacheSpremenljivka['variable']);
			echo '&nbsp;<select name="recode_number_operator[]" onChange="recode_operator_changed(this);">';
			foreach (self::$_operators AS $value => $operator) {
				$selected = ($value == '0') ? ' selected="selected"' : '';
				echo '<option value="'.$value.'"'.$selected.'>'.$operator.'</option>';
			}
			echo '</select>';
			#echo '&nbsp;<input type="text" name="recode_number_search[]" value="0" size="5" autocomplete="off"/>';
				
			echo '<span class="recode_int_first">';
			echo '&nbsp;<input type="text" name="recode_number_search[]" value="0" size="12" autocomplete="off"/>';
			echo '</span>';
			echo '<span class="recode_int_seccond hidden">';
			echo '&nbsp;[<input type="text" name="recode_number_search1[]" value="0" size="5" autocomplete="off"/>,';
			echo '<input type="text" name="recode_number_search2[]" value="1" size="5" autocomplete="off"/>]';
			echo '</span>';
				
			echo '&nbsp;'.$lang['srv_recode_number_to'];
			# imamo rekodiranje v  novo spremenljivko
			$recode['vred_id'] = '-1';
				
			echo '<select name="recode_number_vrednost[]">';
			if (is_array($new_spr_vrednosti) && count($new_spr_vrednosti)>0) {
				foreach ($new_spr_vrednosti AS $oKey => $option) {
					if ($option['variable'] == null) {
						echo '<option disabled="disabled">'.$option['naslov'].'</option>';
					} else {
						$_selected = ($recode['vred_id'] == $option['variable']) ? ' selected="selected"' : '';
						$_label = $option['naslov'].' ['.$option['variable'].']';
						echo '<option value="'.$option['variable'].'"'.$_selected.'>&nbsp;&nbsp;'.$_label.'</option>';
					}
					#	$_label = $option['naslov'].' ['.$option['variable'].']';
					#	echo '<option value="'.$option['id'].'" '.$_selected.'>'.$_label.'</option>';
				}
			}
			echo '</select>';

			echo '&nbsp;<span class="floatRight spaceRight faicon delete_circle icon-orange_link" onclick="recode_delete_numeric(\''.self::$spremenljivka.'\',this);"></span>';
			echo '</li>';	
		}
		
		return;
	}
	
	public function hasRecodedValues() {
		#preštejemo koliko rekodiranj imamo za spremenljivko
		$strSelect = "SELECT count(*) FROM srv_recode WHERE ank_id = '".self::$anketa."' AND spr_id = '".self::$spremenljivka."'";
		$sqlSelect = sisplet_query($strSelect);
		list($count) = mysqli_fetch_row($sqlSelect);
		return (int)$count;
	}
	
	
	public function changeRecodeType() {
		$insertString = "INSERT INTO srv_recode_spremenljivka (ank_id, spr_id, recode_type, to_spr_id) VALUES ('".self::$anketa."', '".self::$spremenljivka."', '".(int)$_POST['recode_type']."', '".(int)$_POST['recodeToSpr']."') ON DUPLICATE KEY UPDATE recode_type = '".(int)$_POST['recode_type']."',  to_spr_id = '".(int)$_POST['recodeToSpr']."'";
		$sqlInsert = sisplet_query($insertString);
		self::displayRecodeType();
	}
	
	public static function displayRecodeType() {
		global $lang;
		$tip = self::$cacheSpremenljivka['tip'];
		if (in_array($tip, array(
				1,	# radio
				2,	# checkbox
				3,	# select
				6,	# multiradio
				16,	# multicheck
				17	# razvrščanje
				))) {
				$displayType=1;
		} else if (in_array($tip, array(
				7,	# number
				18,	# vsota
				20,	# multinumber
				22,	# multinumber
				21,	# textovni
				))) {
				$displayType=2;
		}
		# polovimo osnovne lastnosti rekodiranja
		$selectString = "SELECT recode_type, to_spr_id FROM srv_recode_spremenljivka WHERE ank_id='".self::$anketa."' AND spr_id='".self::$spremenljivka."'";
		$sqlSelect = sisplet_query($selectString);
		if (!$sqlSelect) echo mysqli_error($GLOBALS['connect_db']);
		list($recode_type, $to_spr_id) = mysqli_fetch_row($sqlSelect);

		if ((int)$recode_type == 0) {
			self::LoadSpremenljivkaMissingValues(self::$spremenljivka);
			# polovimo missinge za spremenljivko
			$strSelect = "SELECT search, value, operator FROM srv_recode WHERE ank_id = '".self::$anketa."' AND spr_id = '".self::$spremenljivka."' ORDER BY vrstni_red";
			$sqlSelect = sisplet_query($strSelect);
			if (!$sqlSelect) echo mysqli_error($GLOBALS['connect_db']);
			$recoded = array();
			if (mysqli_num_rows($sqlSelect)) {
				while ($rowSelect = mysqli_fetch_assoc($sqlSelect)) {
					$recoded[$rowSelect['search'].'_'.$rowSelect['operator']] = array('search'=>$rowSelect['search'],'value'=>$rowSelect['value'],'operator'=>$rowSelect['operator']);
				}
			}
		} else {
			
			if ($displayType == 1) {
				# polovimo še vrednosti če imamo rekodirano v drugo spremenljivko
				$qry_str = "select vre1, spr2, vre2 from srv_recode_vrednost WHERE ank_id = '".self::$anketa."' AND spr1 = '".self::$spremenljivka."'";
				$sql = sisplet_query($qry_str);
				$recodedFrom = array();
				while (list($vre1, $spr1, $vre2) = mysqli_fetch_row($sql)) {
					$recodedFrom[$vre1] = $vre2;
				}
			} else {
				# polovimo missinge za spremenljivko
				$strSelect = "SELECT search, vred_id, operator FROM srv_recode_number WHERE ank_id = '".self::$anketa."' AND spr_id = '".self::$spremenljivka."' ORDER BY vrstni_red";
				$sqlSelect = sisplet_query($strSelect);
				if (!$sqlSelect) echo mysqli_error($GLOBALS['connect_db']);
				$recoded = array();
				if (mysqli_num_rows($sqlSelect)) {
					while ($rowSelect = mysqli_fetch_assoc($sqlSelect)) {
						$recoded[$rowSelect['search'].'_'.$rowSelect['operator']] = array('search'=>$rowSelect['search'],'vred_id'=>$rowSelect['vred_id'],'operator'=>$rowSelect['operator']);
					}
				}
			}
		
			self::LoadSpremenljivkaMissingValues($to_spr_id);
			$new_spr_vrednosti = self::$options;
			self::LoadSpremenljivkaMissingValues(self::$spremenljivka);
			
			# preverimo ali spremenljvka obstaja
			#$new_spr_vrednosti = array();
			if ((int)$to_spr_id > 0) {
				$sqlSpremenljivka = sisplet_query("SELECT s.naslov, s.variable, s.tip FROM srv_spremenljivka s WHERE s.id = '$to_spr_id'");
				$rowSpremenljivka = mysqli_fetch_assoc($sqlSpremenljivka);
				
				if (mysqli_num_rows($sqlSpremenljivka) == 0) {
					$to_spr_id = 0;
				}			
			}
		}
		
		echo '<input type="hidden" name="anketa" value="'.self::$anketa.'" autocomplete="off"/>';
		echo '<input type="hidden" name="spr_id" value="'.self::$spremenljivka.'" autocomplete="off"/>';
		echo '<input type="hidden" name="recodeToSpr" value="'.$to_spr_id.'" autocomplete="off"/>';
		echo '<input type="hidden" id="recIsCharts" value="'.((int)(($_GET['t'] == 'charts')||((int)$_POST['recIsCharts'] == 1)) ).'" autocomplete="off"/>';
		

		if ( $_GET['t'] == 'charts' || $_POST['recIsCharts'] == 1 ) {
			# če smo v grafih in smo na spremenljivki katera je že rekodirana iz druge, potem onemogočimo nadaljnje kodiranje
			$strSel = "SELECT count(*) FROM srv_recode_spremenljivka WHERE  to_spr_id = '".self::$spremenljivka."'";
			$qry = sisplet_query($strSel);
			list($cnt) = mysqli_fetch_row($qry);
			if ((int)$cnt > 0) {
				echo $lang['srv_recoded_advancetNote_recoded3'];
				echo self::$cacheSpremenljivka['variable'].' - '.self::$cacheSpremenljivka['naslov'];
				echo $lang['srv_recoded_advancetNote_recoded4'];
				return;
			}
		}
		
		
		if (self::$cacheSpremenljivka['tip'] == 1 || self::$cacheSpremenljivka['tip'] == 3 || self::$cacheSpremenljivka['tip'] == 7) {
			
			if ( (int)$recode_type == 1 && ((int)(($_GET['t'] == 'charts')||((int)$_POST['recIsCharts'] == 1))) ) {
				echo '<br/>';
				echo $lang['srv_recoded_advancetNote'].'<a href="index.php?anketa='.self::$anketa.'&a='.A_COLLECT_DATA.'&m='.M_COLLECT_DATA_RECODING.'">'.$lang['srv_here'].'</a>';
				echo Help::display('srv_recode_chart_advanced');
				echo '<br/>';
				echo '<br/>';
				echo $lang['srv_recoded_advancetNote_recoded1'];
				echo self::$cacheSpremenljivka['variable'];
				echo ' - '.strip_tags(self::$cacheSpremenljivka['naslov']);
				echo $lang['srv_recoded_advancetNote_recoded2'];
				echo $rowSpremenljivka['variable'].' - '.$rowSpremenljivka['naslov'];
				return;
			}
			$sugestedName = strip_tags(self::$cacheSpremenljivka['naslov'].' - recoded');
			echo'<div id="divRecodeSprOption">';
			echo '<label>'.$lang['srv_recode_to_spr'].'</label>';
			if ( $_GET['t'] == 'charts' || $_POST['recIsCharts'] == 1 ) {
				echo $lang['srv_recode_to_spr_same'];
			} else {
				echo '<label><input type="radio" name="recode_type" value="0" '.((int)$recode_type == 0 ? ' checked="checked"' : '').'onchange="changeRecodeType();return false;">'.$lang['srv_recode_to_spr_same'].'</label>';
				echo '<label><input type="radio" name="recode_type" value="1" '.((int)$recode_type == 1 ? ' checked="checked"' : '').'onchange="changeRecodeType();return false;">'.$lang['srv_recode_to_spr_new'].'</label>';
			}
			echo '</div>';
			if ((int)$recode_type == 1) {
				
                echo'<span id="divRecodeSprNew" class="floatRecodeSpremenljivka">';
                
				if ((int)$to_spr_id == 0) {
					echo '<div class="new-spr" style="text-align: right">';
					echo $lang['srv_recode_to_spr_add_spr'].'<br/>';
					echo '<div id="coding_spr_new" >';
					echo '<p>'.$lang['srv_recode_to_spr_name'].' <input type="text" id="rec_spremenljivka_naslov" name="spremenljivka_naslov" default="1" contenteditable="true" value="'.$sugestedName.'" style="width: 123px" />';
					#echo '<a href="#" onclick="recodeSpremenljivkaNew(); return false;">'.$lang['add'].'</a>';
					echo '<a href="#" onclick="recodeSpremenljivkaNew(); return false;""><span class="faicon add small" title="'.$lang['add'].'"></span></a>';
					echo '</p>';
					echo '</div>';
					echo '</div>';
				} else {
					echo '<strong>'.$rowSpremenljivka['variable'].' - '.skrajsaj(strip_tags($rowSpremenljivka['naslov']), 40).'</strong><br/><br/>';
					$sql1 = sisplet_query("SELECT naslov FROM srv_vrednost WHERE spr_id='$to_spr_id' ORDER BY vrstni_red ASC");
					while ($row1 = mysqli_fetch_array($sql1)) {
						if ($rowSpremenljivka['tip'] == 1) {
							echo '<input type="radio" onclick="return false;" /><label> '.$row1['naslov'].'</label>';
							echo '<br/>';
						}
					}
					if (mysqli_num_rows($sql1) == 0) {
						echo '&nbsp;'.$lang['srv_novavrednost'].': '; $margin='0';
					} else { $margin = '23px';
					}
					echo '<input type="text" name="vrednost_new" value="" '.(mysqli_num_rows($sql1)>0?' placeholder="'.$lang['srv_novavrednost'].'" ':'').' style="margin-left:'.$margin.'; width: 80px" /> ';
					echo '<a href="#" onclick="recodeVrednostNew(); return false;"><span class="faicon add small icon-as_link" title="'.$lang['add'].'"></span></a>';
					echo '<br>Napredne spremembe:'.Help::display('srv_recode_advanced_edit');
				}
				echo '</span>';
			}
			echo'<br class="clr" />';
		}
		if ( $displayType == 1 ) {
			if (count(self::$variables)> 0) {
				if ((int)$recode_type == 0) {
					echo '<input type="hidden" name="edit_recode_mv" value="1" autocomplete="off"/>';
				} else {
					# rekodiramo v novo spremenljivko
					echo '<input type="hidden" name="edit_recode_nsmv" value="1" autocomplete="off"/>';
				}
				//echo '<table style="width:65% !important;">';
				echo '<table class="question_recode_table">';
				echo '<tr>';
				echo '<th class="halfWidth" colspan="2">';
				echo $lang['srv_recode_original'];
				echo '</th>';
				echo '<td rowspan="2" style="vertical-align:top;">&nbsp;<span class="sprites arrow_switch"></span>&nbsp;</td>';
				echo '<th class="halfWidth" rowspan="2" style="vertical-align:top;">';
				echo $lang['srv_recode_to'];
				echo '</th>';
				echo '</tr>';

				echo '<tr>';
				echo '<td class="halfWidth anl_ac gray">';
				echo $lang['srv_recode_to_label'];
				echo '</td>';
				echo '<td class="halfWidth anl_ac gray">';
				echo $lang['srv_recode_to_value'];
				echo '</td>';
				echo '</tr>';
					
				foreach (self::$variables AS $vKey => $variable) {
					echo '<tr>';
					echo '<td class="anl_ac">';
					echo $variable['naslov'];
					echo '</td>';
					echo '<td class="anl_ac">';
					echo '&nbsp;&nbsp;['.$variable['variable'].']';
					echo '</td>';
					# spacer
					echo '<td>&nbsp</td>';
					#
					echo '<td>';
					if ((int)$recode_type == 0) {
						# imamo klasično rekodiranje
						echo '<select name="MVFQ_'.$variable['variable'].'">';
						foreach (self::$options AS $oKey => $option) {
								
							if ($option['variable'] == null) {
								echo '<option disabled="disabled">'.$option['naslov'].'</option>';
							} else {
								$_selected = ((isset($recoded[$variable['variable'].'_0']) && $recoded[$variable['variable'].'_0']['value'] == $option['variable'])
										|| (!isset($recoded[$variable['variable'].'_0']) && $variable['variable'] == $option['variable'])) ? 'selected="selected"' : '';
								$_label = (( $variable['variable'] == $option['variable']))
									? '('.$lang['srv_recode_valid'].') '.$option['naslov'].' ['.$option['variable'].']'
									: $option['naslov'].' ['.$option['variable'].']';
								echo '<option value="'.$option['variable'].'" '.$_selected.'>&nbsp;&nbsp;'.$_label.'</option>';
							}
						}
						echo '</select>';
					} else {
						# imamo rekodiranje v  novo spremenljivko
						
						if (!isset($recodedFrom[$vKey])) {
								$recodedFrom[$vKey] = '-1';
						}
						echo '<select name="MVSNFQ_'.$vKey.'">';
						if (is_array($new_spr_vrednosti) && count($new_spr_vrednosti)>0) {
							foreach ($new_spr_vrednosti AS $oKey => $option) {
								if ($option['variable'] == null) {
									echo '<option disabled="disabled">'.$option['naslov'].'</option>';
								} else {
									
									if (is_numeric($oKey)) {
										$_selected = (isset($recodedFrom[$vKey]) && $recodedFrom[$vKey] == $oKey)
										? ' selected="selected"'
										: '';
										$_label = $option['naslov'].' ['.$option['variable'].']';
										$value = (int)$oKey;
									} else {
										$_selected = (isset($recodedFrom[$vKey]) && $recodedFrom[$vKey] == $option['variable'])
											? ' selected="selected"' 
											: '';
										$_label = $option['naslov'].' ['.$option['variable'].']';
										$value = (int)$option['type'] == 0 && (int)$option['id'] > 0 ? $option['id'] : $option['variable'];
									}
									echo '<option value="'.$value.'" '.$_selected.'>&nbsp;&nbsp;'.$_label.'</option>';
								}
							}
						}
						echo '</select>';
					}
					echo '</td>';
					echo '</tr>';
				}
				echo '</table>';
			}
		} else if (	$displayType == 2) {
			# number
			if ((int)$recode_type == 0) {
				echo '<input type="hidden" name="edit_recode_number" value="1" autocomplete="off"/>';
				echo '<ul id="recode_number_sort" class="recode_number_sort">';
				if (count($recoded)> 0) {
					foreach ($recoded AS $rKey => $recode) {

						echo '<li>';
						echo '<span class="faicon move_updown moveY"></span>';
						printf($lang['srv_recode_number_if'],self::$cacheSpremenljivka['variable']);
						echo '&nbsp;<select name="recode_number_operator[]" onChange="recode_operator_changed(this);">';
						foreach (self::$_operators AS $value => $operator) {
							$selected = ($value == $recode['operator']) ? ' selected="selected"' : '';
							echo '<option value="'.$value.'"'.$selected.'>'.$operator.'</option>';
						}
						echo '</select>';
						$rSearchInterval = explode(',',$recode['search']);
	
						echo '<span class="recode_int_first'.($recode['operator'] != 6 ? '' : ' hidden').'">';
						echo '&nbsp;<input type="text" name="recode_number_search[]" value="'.($rSearchInterval[0]).'" size="12" autocomplete="off"/>';
						echo '</span>';
						echo '<span class="recode_int_seccond'.($recode['operator'] != 6 ? ' hidden' : '').'">';
						echo '&nbsp;[<input type="text" name="recode_number_search1[]" value="'.($rSearchInterval[0]).'" size="5" autocomplete="off"/>,';
						echo '<input type="text" name="recode_number_search2[]" value="'.($rSearchInterval[1]).'" size="5" autocomplete="off"/>]';
						echo '</span>';
	
						echo '&nbsp;'.$lang['srv_recode_number_to'];
						$is_missing_value = false;
						echo '<select name="recode_number_type" onChange="recode_number_type_changed(this);">';
						foreach (self::$options AS $oKey => $option) {
							if ($oKey == '_0_' || $oKey == '_1_' || $oKey == '_2_') {
								# privzeto izberemo prvi odgovor - veljavni, nato spodaj popravimo
								$_value = ($oKey == '_0_') ? '_' : null;
								$_selected = ($oKey == '_0_' ? 'selected="selected"' : 'disabled="disabled"');
								$_label = $option['naslov'];
							} else {
								$_value = $option['variable'];
								if ($oKey == $recode['value']) {
									$is_missing_value = true;
									$_selected = 'selected="selected"';
								} else {
									$_selected = '';
								}
								$_label = '&nbsp;&nbsp;'.$option['naslov'].' ['.$option['variable'].']';
							}
							echo '<option value="'.$_value.'" '.$_selected.'>'.$_label.'</option>';
						}
						echo '</select>';
	
						echo '&nbsp;<input type="text" name="recode_number_value[]" value="'.$recode['value'].'" size="5" '.($is_missing_value ? ' class="hidden"' : '').' autocomplete="off"/>';
						echo '&nbsp;<span class="floatRight spaceRight faicon delete_circle icon-orange_link" onclick="recode_delete_numeric(\''.self::$spremenljivka.'\',this);"></span>';
						echo '</li>';
					}
				}
				echo '</ul>';
				echo '<script>$(\'#recode_number_sort\').sortable({ items: \'li\', axis: \'y\', scroll: \'false\', handle: \'span.move_updown\', forcePlaceholderSize: \'true\', placeholder: "ui-recode-placeholder"});</script>';
				echo '<span onclick="recode_add_numeric(\''.self::$spremenljivka.'\');" class="pointer"><span class="faicon add small icon-as_link" title="'.$lang['srv_recode_add_number'].'"></span> '.$lang['srv_recode_add_number'].'</span>';
			} else {
				
				# number
				# recode to new spr
				echo '<input type="hidden" name="edit_recode_number" value="1" autocomplete="off"/>';
				echo '<ul id="recode_number_sort" class="recode_number_sort">';
				if (count($recoded)> 0) {
					foreach ($recoded AS $rKey => $recode) {

						echo '<li>';
						echo '<span class="faicon move_updown moveY"></span>';
						printf($lang['srv_recode_number_if'],self::$cacheSpremenljivka['variable']);
						echo '&nbsp;<select name="recode_number_operator[]" onChange="recode_operator_changed(this);">';
						foreach (self::$_operators AS $value => $operator) {
							$selected = ($value == $recode['operator']) ? ' selected="selected"' : '';
							echo '<option value="'.$value.'"'.$selected.'>'.$operator.'</option>';
						}
						echo '</select>';
						$rSearchInterval = explode(',',$recode['search']);
				
						echo '<span class="recode_int_first'.($recode['operator'] != 6 ? '' : ' hidden').'">';
						echo '&nbsp;<input type="text" name="recode_number_search[]" value="'.($rSearchInterval[0]).'" size="12" autocomplete="off"/>';
						echo '</span>';
						echo '<span class="recode_int_seccond'.($recode['operator'] != 6 ? ' hidden' : '').'">';
						echo '&nbsp;[<input type="text" name="recode_number_search1[]" value="'.($rSearchInterval[0]).'" size="5" autocomplete="off"/>,';
						echo '<input type="text" name="recode_number_search2[]" value="'.($rSearchInterval[1]).'" size="5" autocomplete="off"/>]';
						echo '</span>';
				
						echo '&nbsp;'.$lang['srv_recode_number_to'];
						if (!isset($recodedFrom[$rKey])) {
							$recodedFrom[$rKey] = '-1';
						}
						# imamo rekodiranje v  novo spremenljivko
						echo '<select name="recode_number_vrednost[]">';
						if (is_array($new_spr_vrednosti) && count($new_spr_vrednosti)>0) {
							foreach ($new_spr_vrednosti AS $oKey => $option) {
								if ($option['variable'] == null) {
									echo '<option disabled="disabled">'.$option['naslov'].'</option>';
								} else {
									if ($option['type'] == 0) {
										$value = $oKey;
										$_selected = ($recode['vred_id'] == $oKey) ? ' selected="selected"' : '';
									} else {
										$value = $option['variable'];
										$_selected = ($recode['vred_id'] == $option['variable']) ? ' selected="selected"' : '';
									} 
										
									$_label = $option['naslov'].' ['.$option['variable'].']';
									echo '<option value="'.$value.'"'.$_selected.'>&nbsp;&nbsp;'.$_label.'</option>';
								}
								
						
						
							#	$_label = $option['naslov'].' ['.$option['variable'].']';
							#	echo '<option value="'.$option['id'].'" '.$_selected.'>'.$_label.'</option>';
							}
						}
						echo '</select>';
						echo '&nbsp;<span class="floatRight spaceRight faicon delete_circle icon-orange_link" onclick="recode_delete_numeric(\''.self::$spremenljivka.'\',this);"></span>';
						echo '</li>';
					}
				}
				echo '</ul>';
				echo '<script>$(\'#recode_number_sort\').sortable({ items: \'li\', axis: \'y\', scroll: \'false\', handle: \'span.move_updown\', forcePlaceholderSize: \'true\', placeholder: "ui-recode-placeholder"});</script>';
				echo '<span onclick="recode_add_numeric(\''.self::$spremenljivka.'\');" class="pointer"><span class="faicon add small icon-as_link" title="'.$lang['srv_recode_add_number'].'"></span> '.$lang['srv_recode_add_number'].'</span>';			}
		} else {
			echo '<br>'.$lang['srv_recoding_not_set_jet'].'('.$tip.')<br>';
		}
	}
	
	function SetRecodeNewVrednost() {
		# pobrišemo morebtne vrednosti v srv_recode (če je bilo predhodno nastavljeno klasično rekodiranje)
		$sqlD = sisplet_query("DELETE FROM srv_recode WHERE ank_id = '".self::$anketa."' AND spr_id = '".$_REQUEST['spr_id']."'");
		if (!$sqlD) echo mysqli_error($GLOBALS['connect_db']);
		sisplet_query("COMMIT");
		
		$newSpr = $_REQUEST['recodeToSpr'];
		$_for_replace = "";
		if ((int)$newSpr > 0)
		foreach ($_REQUEST as $key => $newVrednost) {
			if (substr($key, 0, 7) == 'MVSNFQ_' && trim($newVrednost) != '') {
				# id stare vrednosti
				$oldVrednost = substr($key, 7);
				if ($_for_replace != "") {
					$_for_replace .= ",";
				}
				$_for_replace .= " ('".self::$anketa."','".self::$spremenljivka."','$oldVrednost','$newSpr','$newVrednost') ";
			}
			
		}
		# najprej pobrišemo vse obstoječe vrednosti
		$sql = sisplet_query("DELETE FROM srv_recode_vrednost WHERE ank_id = '".self::$anketa."' AND spr1 = '".self::$spremenljivka."'");
		if (!$sql) echo mysqli_error($GLOBALS['connect_db']);
		sisplet_query("COMMIT");
		
		# če moramo uporabiti zamenjave:
		if ($_for_replace != "") {
			$insertString = 'INSERT INTO srv_recode_vrednost (ank_id, spr1, vre1, spr2, vre2) VALUES '.$_for_replace;
			$sql1 = sisplet_query($insertString);
		}
		sisplet_query("COMMIT");
			
	}
	
}