summaryrefslogtreecommitdiffstats
path: root/main/survey/app/Controllers/Vprasanja/DoubleController.php
blob: 83a68afc9a9477ff8b13ab44e4e5b51aade1110a (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
<?php
/***************************************
 * Description: Dobule grid in double checkbox
 *
 * Vprašanje je prisotno:
 *  tip 6 - enota 3
 *  tip 16 - enota 3
 *
 * Izris dvojnega multigrida/multicheckboxa
 * Autor: Robert Šmalc
 * Created date: 01.03.2016
 *****************************************/

namespace App\Controllers\Vprasanja;

// Osnovni razredi
use App\Controllers\Controller;
use App\Controllers\HelperController as Helper;
use App\Controllers\LanguageController as Language;
use App\Models\Model;
use enkaParameters;


class DoubleController extends Controller
{
    public function __construct()
    {
        parent::getGlobalVariables();
    }

    /************************************************
     * Get instance
     ************************************************/
    private static $_instance;

    public static function getInstance()
    {
        if (self::$_instance)
            return self::$_instance;

        return new DoubleController();
    }

    /**
     * @desc prikaze vnosno polje za doublegrid
     */
    public function grid($spremenljivka)
    {
        $loop_id = get('loop_id') == null ? " IS NULL" : " = '" . get('loop_id') . "'";

        // Pri vpogledu moramo skriti name atribut pri loop spremenljivkah, da se izpise prava vrednost
        $hideName = ((get('loop_id') != null) && ($_GET['m'] == 'quick_edit')) ? true : false;

        $row = Model::select_from_srv_spremenljivka($spremenljivka);

        $spremenljivkaParams = new enkaParameters($row['params']);
        $hideLabels = false;
        $gridWidth = $spremenljivkaParams->get('gridWidth');
        switch ($gridWidth) {
            case -2:
                $hideLabels = true;
                $gridWidth = 30;    // just in case če se kje kaj računa, itak je skrit.
                break;
            case -1:
            case 0:
                $gridWidth = 30;
                break;
        }
         //$css = ' style = "width: '.$gridWidth.'%;" ';

        // izracuni za sirino celic
        $size = 2 * $row['grids'];
        $colspan = $row['grids'];

        # polovimo vrednosti gridov, prevedmo naslove in hkrati preverimo ali imamo missinge
        $srv_grids = array();
        $mv_count = 0; # koliko je stolpcev z manjkajočimi vrednostmi
        # če polje other != 0 je grid kot missing
        $sql_grid = sisplet_query("SELECT * FROM srv_grid WHERE spr_id='$row[id]' AND part='1' ORDER BY vrstni_red");

        $space = false;
        while ($row_grid = mysqli_fetch_assoc($sql_grid)) {
            # priredimo naslov če prevajamo anketo
            $naslov = Language::srv_language_grid($row['id'], $row_grid['id']);
            if ($naslov != '') {
                $row_grid['naslov'] = $naslov;
            }
            $srv_grids[$row_grid['id']] = $row_grid;
            # če je označena kot manjkajoča jo prištejemo k manjkajočim
            if ($row_grid['other'] != 0) {
                $mv_count++;
                $colspan++;

                if (!$space) {
                    $colspan++;
                    $space = true;
                }
            }

        }

        //se za desni del grida
        $sql_grid2 = sisplet_query("SELECT * FROM srv_grid WHERE spr_id='$row[id]' AND part='2' ORDER BY vrstni_red");
		
		$indexLanguage = 1;
        while ($row_grid2 = mysqli_fetch_assoc($sql_grid2)) {
            # priredimo naslov če prevajamo anketo
            //$naslov = Language::srv_language_grid($row['id'], $row_grid2['id']);
            $naslov = Language::srv_language_grid($row['id'], $indexLanguage);
            if ($naslov != '') {
                $row_grid2['naslov'] = $naslov;
            }
            $srv_grids2[$row_grid2['id']] = $row_grid2;
            # če je označena kot manjkajoča jo prištejemo k manjkajočim
            if ($row_grid2['other'] != 0) {
                $mv_count++;
            }
			
			$indexLanguage++;
        }

        # če imamo mankajoče potem dodamo še en prazen stolpec za razmak
        if ($mv_count > 0) {
            $size += 1 + $mv_count;
        }

        # če imamo nastavljno sirino prvega grida ostalih ne nastavljamo
        if ($gridWidth == 30) {
            $cellsize = round(80 / $size);
        } else {
            $cellsize = 'auto';
        }

        $spacesize = round(80 / $size / 4);

        $bg = 1;

        echo '<table class="grid_table doublegrid">' . "\n";

        if ($hideLabels == false) {
            echo '<colgroup class="question">';
            echo '<col class="width_' . $gridWidth . '">';
            echo '</colgroup>';
            echo '<colgroup>';
            echo '<col class="space">';
            echo '</colgroup>';
        }
        
        echo '<colgroup class="category">';
        for ($i = 1; $i <= $row['grids']; $i++)
            echo '<col>';
        echo '</colgroup>';
        
        if ($mv_count > 0) {
            echo '<colgroup>';
            echo '<col class="space">';
            echo '</colgroup>';
            echo '<colgroup class="missing">';
            for ($i = 1; $i <= $mv_count / 2; $i++)
                echo '<col>';
            echo '</colgroup>';
        }

        echo '<colgroup>';
        echo '<col class="space">';
        echo '<col class="space">';
        echo '</colgroup>';

        echo '<colgroup class="category">';
        for ($i = 1; $i <= $row['grids']; $i++)
            echo '<col>';
        echo '</colgroup>';
        if ($mv_count > 0) {
            echo '<colgroup>';
            echo '<col class="space">';
            echo '</colgroup>';
            echo '<colgroup class="missing">';
            for ($i = 1; $i <= $mv_count / 2; $i++)
                echo '<col>';
            echo '</colgroup>';
        }

        echo '<thead>';
        
		//izpis podnaslovov posameznih delov grida
		# priredimo podnaslovov če je prevod ankete
		$podnaslov1 = Language::srv_language_grid_podnaslov($row['id'], 1);
		$podnaslov2 = Language::srv_language_grid_podnaslov($row['id'], 2);
		if ($podnaslov1 != '') {				
			$row['grid_subtitle1'] = $podnaslov1;
		}
		if ($podnaslov2 != '') {				
			$row['grid_subtitle2'] = $podnaslov2;
		}
		# priredimo podnaslovov če je prevod ankete - konec
		
        echo '	<tr>' . "\n\r";
        if ($hideLabels == false) {
            echo '		<td></td>' . "\n";
            echo '		<td></td>' . "\n";
        }
        echo '		<td colspan="' . $colspan . '">' . $row['grid_subtitle1'] . '</td>' . "\n";
        echo '		<td></td>';
        echo '		<td></td>';
        echo '		<td colspan="' . $colspan . '">' . $row['grid_subtitle2'] . '</td>' . "\n";
        echo '	</tr>' . "\n\r";

        echo '	<tr>' . "\n\r";
        if ($hideLabels == false) {
            echo '		<td></td>' . "\n";
            echo '		<td></td>' . "\n";
        }
        
        # Izpišemo TOP vrstico z labelami
        if (count($srv_grids) > 0) {
            $first_missing_value = true;
            foreach ($srv_grids AS $i => $srv_grid) {
                if ((string)$srv_grid['other'] != '0' && $first_missing_value == true) {
                    # dodamo spejs pred manjkajočimi vrednostmi
                    echo '		<td></td>' . "\n";
                    $first_missing_value = false;
                }

                // Datapiping
                $srv_grid['naslov'] = Helper::dataPiping($srv_grid['naslov']);
                # izpišemo labelo grida
                echo '		<td class="' . ($srv_grid['other'] == 0 ? 'category' : 'missing') . '">' . $srv_grid['naslov'] . '</td>' . "\n";
            }
        }

        #double grid space        
        echo '<td></td>';
        echo '<td class="double"></td>';

        //se za desni del grida
        if (count($srv_grids2) > 0) {
            $first_missing_value = true;
            foreach ($srv_grids2 AS $i => $srv_grid) {
                if ((string)$srv_grid['other'] != '0' && $first_missing_value == true) {
                    # dodamo spejs pred manjkajočimi vrednostmi
                    echo '		<td></td>' . "\n";
                    $first_missing_value = false;
                }

                // Datapiping
                $srv_grid['naslov'] = Helper::dataPiping($srv_grid['naslov']);

                # izpišemo labelo grida
                echo '		<td class="' . ($srv_grid['other'] == 0 ? 'category' : 'missing') . '">' . $srv_grid['naslov'] . '</td>' . "\n";
            }
        }
        echo '	</tr>' . "\n";

        echo '</thead>';

        echo '<tbody>';

        $bg++;

        $orderby = Model::generate_order_by_field($spremenljivka, get('usr_id'));

        # cache tabele srv_data_checkgrid, da se ne dela vsakic posebej nov query (preberemo enkrat vse odgovore userja) - za part 1
        $srv_data_grid = array();
        $sql_grid = sisplet_query("SELECT d.* FROM srv_data_checkgrid" . get('db_table') . " d, srv_grid g WHERE d.spr_id='$row[id]' AND d.usr_id='" . get('usr_id') . "' AND d.loop_id $loop_id AND d.grd_id=g.id AND g.part='1' AND g.spr_id='$row[id]'");
        while ($row_grid = mysqli_fetch_array($sql_grid)) {
            $srv_data_grid[$row_grid['vre_id']] = $row_grid;
        }
        # cache tabele srv_data_checkgrid, da se ne dela vsakic posebej nov query (preberemo enkrat vse odgovore userja) - za part 2
        $srv_data_grid2 = array();
        $sql_grid = sisplet_query("SELECT d.* FROM srv_data_checkgrid" . get('db_table') . " d, srv_grid g WHERE d.spr_id='$row[id]' AND d.usr_id='" . get('usr_id') . "' AND d.loop_id $loop_id AND d.grd_id=g.id AND g.part='2' AND g.spr_id='$row[id]'");
        while ($row_grid = mysqli_fetch_array($sql_grid)) {
            $srv_data_grid2[$row_grid['vre_id']] = $row_grid;
        }

        # loop skozi srv_vrednost, da izpišemo vrstice z vrednostmi
        $sql1 = sisplet_query("SELECT * FROM srv_vrednost WHERE spr_id='$row[id]' ORDER BY FIELD(vrstni_red, $orderby)");
        while ($row1 = mysqli_fetch_array($sql1)) {
            # po potrebi prevedemo naslov
            $naslov = Language::getInstance()->srv_language_vrednost($row1['id']);
            if ($naslov != '') {
                $row1['naslov'] = $naslov;
            }
            # preverimo izbrano vrednost
            $grid_id = isset($srv_data_grid[$row1['id']]['grd_id']) ? $srv_data_grid[$row1['id']]['grd_id'] : "";
            $grid_id2 = isset($srv_data_grid2[$row1['id']]['grd_id']) ? $srv_data_grid2[$row1['id']]['grd_id'] : "";

            # ugotovimo ali je na katerem gridu predhodno izbran missing
            $is_missing = false;
            if (count($srv_grids) > 0) {
                foreach ($srv_grids AS $i => $srv_grid) {
                    if ($srv_grid['other'] != 0 && $srv_grids[$i]['id'] == $grid_id) {
                        $is_missing = true;
                    }
                }
            }

            // Datapiping
            $row1['naslov'] = Helper::dataPiping($row1['naslov']);

            echo '	<tr id="vrednost_if_' . $row1['id'] . '" ' . (($row1['hidden'] == 1) ? 'style="display:none"' : '') . (($row1['hidden'] == 2) ? 'class="answer-disabled"' : '') . '>' . "\n";
            if ($hideLabels == false) {
                echo '		<td class="question">';
                echo $row1['naslov'];
                if ($row1['other'] == 1) {
                    $sql3 = sisplet_query("SELECT text FROM srv_data_text" . get('db_table') . " WHERE spr_id='$spremenljivka' AND vre_id='$row1[id]' AND usr_id='" . get('usr_id') . "' AND loop_id $loop_id");
                    $row3 = mysqli_fetch_array($sql3);

                    $otherWidth = ($spremenljivkaParams->get('otherWidth') ? $spremenljivkaParams->get('otherWidth') : -1);
                    $otherHeight = ($spremenljivkaParams->get('otherHeight') ? $spremenljivkaParams->get('otherHeight') : 1);

                    if ($otherHeight > 1)
                        echo ' <textarea name="textfield_' . $row1['id'] . '" rows="' . $otherHeight . '" style="' . ($otherWidth != -1 ? ' width:' . $otherWidth . '%;' : '') . '" ' . ($is_missing ? ' disabled' : '') . '>' . ($is_missing ? '' : $row3['text']) . '</textarea>';
                    else
                        echo ' <input type="text" name="textfield_' . $row1['id'] . '" value="' . ($is_missing ? '' : $row3['text']) . '" style="' . ($otherWidth != -1 ? ' width:' . $otherWidth . '%;' : '') . '" ' . ($is_missing ? ' disabled' : '') . ' />';

                    //echo ' <input type="text" name="textfield_'.$row1['id'].'" value="'.($is_missing ? '' : $row3['text']).'" '.($is_missing ? ' disabled' :'').'>';
                }
                echo '</td>' . "\n";
                echo '<td></td>' . "\n";
            }


            if (count($srv_grids) > 0) {
                $first_missing_value = true;
                foreach ($srv_grids AS $i => $srv_grid) {
                    if ((string)$srv_grid['other'] != '0' && $first_missing_value == true) {
                        # dodamo spejs pred manjkajočimi vrednostmi
                        echo '		<td></td>' . "\n";
                        $first_missing_value = false;
                    }

                    $value = $srv_grids[$i]['id'];
                    # izpišemo radio grida

                    if ($srv_grid['other'] != 0) {
                        # imamo missing vrednost
                        echo '<td class="missing">';
                        echo '<label for="grid_missing_value_' . $row1['id'] . '_grid_' . $value . '">';
                        echo '<input type="radio" ' . (!$hideName ? ' name="vrednost_' . $row1['id'] . '"' : '') . ' id="grid_missing_value_' . $row1['id'] . '_grid_' . $value . '" value="' . $value . '"' . (($grid_id == $value && $grid_id != '') ? ' checked' : '') . ' data-calculation="0" onclick="checkChecked(this); checkBranching(); setCheckedClass(this, \'6-3-1\', ' . $row1['id'] . ');">';

                        // Font awesome
                        echo '<span class="enka-checkbox-radio ' . (($row1['hidden'] == 2) ? ' answer-disabled' : '') . '"' .
                            ((Helper::getCustomCheckbox() != 0) ? (' style="font-size:' . Helper::getCustomCheckbox().'px;"') : '').
                            '></span>';

                        echo '</label>';
                        echo '</td>' . "\n";
                    } else {
                        # ni missing vrednost
                        echo '<td class="category">';
                        echo '<label for="vrednost_' . $row1['id'] . '_grid_' . $value . '">';
                        echo '<input type="radio" ' . (!$hideName ? ' name="vrednost_' . $row1['id'] . '"' : '') . ' id="vrednost_' . $row1['id'] . '_grid_' . $value . '" value="' . $value . '"' . (($grid_id == $value && $grid_id != '' && !$is_missing) ? ' checked' : '') . ($is_missing ? ' disabled' : '') . ' data-calculation="' . $srv_grids[$i]['variable'] . '" onclick="checkChecked(this); checkBranching(); setCheckedClass(this, \'6-3-1\', ' . $row1['id'] . ');">';

                        // Font awesome
                        echo '<span class="enka-checkbox-radio ' . (($row1['hidden'] == 2) ? ' answer-disabled' : '') . '"' .
                            ((Helper::getCustomCheckbox() != 0) ? (' style="font-size:' . Helper::getCustomCheckbox().'px;"') : '').
                            '></span>';

                        echo '</label>';
                        echo '</td>' . "\n";
                    }
                }
            }

            #double grid space
            echo '<td></td>';
            echo '<td class="double"></td>';


            //DESNI DEL GRIDA
            # ugotovimo ali je na katerem gridu predhodno izbran missing
            $is_missing = false;
            if (count($srv_grids2) > 0) {
                foreach ($srv_grids2 AS $i => $srv_grid) {
                    if ($srv_grid['other'] != 0 && $srv_grids2[$i]['id'] == $grid_id2) {
                        $is_missing = true;
                    }
                }
            }
            if (count($srv_grids2) > 0) {
                $first_missing_value = true;
                foreach ($srv_grids2 AS $i => $srv_grid) {
                    if ((string)$srv_grid['other'] != '0' && $first_missing_value == true) {
                        # dodamo spejs pred manjkajočimi vrednostmi
                        echo '		<td></td>' . "\n";
                        $first_missing_value = false;
                    }

                    $value = $srv_grids2[$i]['id'];
                    # izpišemo radio grida

                    if ($srv_grid['other'] != 0) {
                        # imamo missing vrednost
                        echo '<td class="missing">';
                        echo '<label for="grid_missing_value_' . $row1['id'] . '_grid_' . $value . '_part_2">';
                        echo '<input type="radio" ' . (!$hideName ? '  name="vrednost_' . $row1['id'] . '_part_2"' : '') . ' id="grid_missing_value_' . $row1['id'] . '_grid_' . $value . '_part_2" value="' . $value . '"' . (($grid_id2 == $value && $grid_id2 != '') ? ' checked' : '') . ' data-calculation="0" onclick="checkChecked(this); checkBranching(); setCheckedClass(this, \'6-3-2\', ' . $row1['id'] . ');">';

                        // Font awesome
                        echo '<span class="enka-checkbox-radio ' . (($row1['hidden'] == 2) ? ' answer-disabled' : '') . '"' .
                            ((Helper::getCustomCheckbox() != 0) ? (' style="font-size:' . Helper::getCustomCheckbox().'px;"') : '').
                            '></span>';

                        echo '</label>';
                        echo '</td>' . "\n";
                    } else {
                        # ni missing vrednost
                        echo '<td class="category">';
                        echo '<label for="vrednost_' . $row1['id'] . '_grid_' . $value . '_part_2">';
                        echo '<input type="radio" ' . (!$hideName ? '  name="vrednost_' . $row1['id'] . '_part_2"' : '') . ' id="vrednost_' . $row1['id'] . '_grid_' . $value . '_part_2" value="' . $value . '"' . (($grid_id2 == $value && $grid_id2 != '' && !$is_missing) ? ' checked' : '') . ($is_missing ? ' disabled' : '') . ' data-calculation="' . $srv_grids2[$i]['variable'] . '" onclick="checkChecked(this); checkBranching(); setCheckedClass(this, \'6-3-2\', ' . $row1['id'] . ');">';

                        // Font awesome
                        echo '<span class="enka-checkbox-radio ' . (($row1['hidden'] == 2) ? ' answer-disabled' : '') . '"' .
                            ((Helper::getCustomCheckbox() != 0) ? (' style="font-size:' . Helper::getCustomCheckbox().'px;"') : '').
                            '></span>';

                        echo '</label>';
                        echo '</td>' . "\n";
                    }
                }
            }

            echo '	</tr>' . "\n";

            $bg++;
        }

        echo '</tbody>';

        echo '</table>' . "\n";
    }

    /**
     * @desc prikaze vnosno polje za doublecheckgrid - TODO!!
     */
    public function checkGrid($spremenljivka)
    {
        $row = Model::select_from_srv_spremenljivka($spremenljivka);

        $loop_id = get('loop_id') == null ? " IS NULL" : " = '" . get('loop_id') . "'";

        // izracuni za sirino celic
        $size = 2 * $row['grids'];
        $colspan = $row['grids'];

        $spremenljivkaParams = new enkaParameters($row['params']);
        $hideLabels == false;
        $gridWidth = $spremenljivkaParams->get('gridWidth');
        switch ($gridWidth) {
            case -2:
                $hideLabels = true;
                $gridWidth = 30;    // just in case če se kje kaj računa, itak je skrit.
                break;
            case -1:
            case 0:
                $gridWidth = 30;
                break;
        }
         
        $css = ' style = "width: ' . $gridWidth . '%;" ';

        # polovimo vrednosti gridov, prevedmo naslove in hkrati preverimo ali imamo missinge
        $srv_grids1 = array();
        $srv_grids2 = array();
        $mv_count = 0; # koliko je stolpcev z manjkajočimi vrednostmi
        # če polje other != 0 je grid kot missing
        //$sql_grid = sisplet_query("SELECT * FROM srv_grid WHERE spr_id='$row[id]' ORDER BY part, vrstni_red");
        $sql_grid1 = sisplet_query("SELECT * FROM srv_grid WHERE spr_id='$row[id]' AND part = '1' ORDER BY vrstni_red");
		$sql_grid2 = sisplet_query("SELECT * FROM srv_grid WHERE spr_id='$row[id]' AND part = '2' ORDER BY vrstni_red");
        
		$space = false;
		
		//levi del
        while ($row_grid1 = mysqli_fetch_assoc($sql_grid1)) {
            # priredimo naslov če prevajamo anketo
            $naslov = Language::srv_language_grid($row['id'], $row_grid1['id']);
            if ($naslov != '') {
                $row_grid1['naslov'] = $naslov;
            }
            $srv_grids1[$row_grid1['id']] = $row_grid1;
            # če je označena kot manjkajoča jo prištejemo k manjkajočim
            if ($row_grid1['other'] != 0) {
                $mv_count++;

                if ($row_grid1['part'] == 1)
                    $colspan++;

                if (!$space) {
                    $colspan++;
                    $space = true;
                }
            }
        }
		
		//desni del
		$indexLanguage = 1;
        while ($row_grid2 = mysqli_fetch_assoc($sql_grid2)) {
            # priredimo naslov če prevajamo anketo
            $naslov = Language::srv_language_grid($row['id'], $indexLanguage);
            if ($naslov != '') {
                $row_grid2['naslov'] = $naslov;
            }
            $srv_grids2[$row_grid2['id']] = $row_grid2;
            # če je označena kot manjkajoča jo prištejemo k manjkajočim
            if ($row_grid2['other'] != 0) {
                $mv_count++;

                if ($row_grid2['part'] == 1)
                    $colspan++;

                if (!$space) {
                    $colspan++;
                    $space = true;
                }
            }
			$indexLanguage++;
        }

        echo '      <table class="grid_table doublecheckgrid">' . "\n";        
        if ($hideLabels == false) {
            echo '<colgroup class="question">';
            echo '<col class="width_' . $gridWidth . '">';
            echo '</colgroup>';
            echo '<colgroup>';
            echo '<col class="space">';
            echo '</colgroup>';
        }
        echo '<colgroup class="category">';
        for ($i = 1; $i <= $row['grids']; $i++)
            echo '<col>';
        echo '</colgroup>';
        if ($mv_count > 0) {
            echo '<colgroup>';
            echo '<col class="space">';
            echo '</colgroup>';
            echo '<colgroup class="missing">';
            for ($i = 1; $i <= $mv_count / 2; $i++)
                echo '<col>';
            echo '</colgroup>';
        }

        echo '<colgroup>';
        echo '<col class="space">';
        echo '<col class="space">';
        echo '</colgroup>';

        echo '<colgroup class="category">';
        for ($i = 1; $i <= $row['grids']; $i++)
            echo '<col>';
        echo '</colgroup>';
        if ($mv_count > 0) {
            echo '<colgroup>';
            echo '<col class="space">';
            echo '</colgroup>';
            echo '<colgroup class="missing">';
            for ($i = 1; $i <= $mv_count / 2; $i++)
                echo '<col>';
            echo '</colgroup>';
        }

        echo '<thead>';

        //ipis podnaslovom posameznih delv grida
        echo '	<tr>' . "\n\r";
        if ($hideLabels == false) {
            echo '		<td></td>' . "\n";
            echo '		<td></td>' . "\n";
        }
        echo '		<td colspan="' . $colspan . '">' . $row['grid_subtitle1'] . '</td>' . "\n";
        echo '		<td></td>';
        echo '		<td></td>';
        echo '		<td colspan="' . $colspan . '">' . $row['grid_subtitle2'] . '</td>' . "\n";
        echo '	</tr>' . "\n\r";

        echo '        <tr>' . "\n";
        if ($hideLabels == false) {
            echo '          <td></td>' . "\n";
            echo '          <td></td>' . "\n";
        }

        # če imamo mankajoče potem dodamo še en prazen stolpec za razmak
        if ($mv_count > 0) {
            $size += 1 + $mv_count;
        }
        # če imamo enoto povečamo št. stoplcev
        if ($row['enota'] == 1) {
            $size += 2;
        }

        //ce imamo nastavljno sirino prvega grida ostalih ne nastavljamo
        if ($gridWidth == 30)
            $cellsize = round(80 / $size);
        else
            $cellsize = 'auto';

        $spacesize = round(80 / $size / 4);

        $taWidth = ($spremenljivkaParams->get('taWidth') ? $spremenljivkaParams->get('taWidth') : -1);
        $taHeight = ($spremenljivkaParams->get('taHeight') ? $spremenljivkaParams->get('taHeight') : 1);
        //default sirina
        if ($taWidth == -1)
            //$taWidth = 10;
            $taWidth = round(50 / $size);

        $bg = 1;

        # Izpišemo TOP vrstico z labelami
        if (count($srv_grids1) > 0) {
            $first_missing_value = true;
            $count = 1;
            foreach ($srv_grids1 AS $g_id => $srv_grid) {
                if ((string)$srv_grid['other'] != '0' && $first_missing_value == true) {
                    # dodamo spejs pred manjkajočimi vrednostmi
                    echo '<td></td>';
                    $first_missing_value = false;

                    $count++;
                }

                // Datapiping
                $srv_grid['naslov'] = Helper::dataPiping($srv_grid['naslov']);

                # izpišemo labelo grida
                echo '<td class="' . ($srv_grid['other'] == 0 ? 'category' : 'missing') . '">' . $srv_grid['naslov'] . '</td>' . "\n";

                //vmesno polje z mejo
                if ($count == $colspan) {
                    echo '<td></td><td class="double"></td>';
                    $first_missing_value = true;
                }
                $count++;
            }
        }
		
		if (count($srv_grids2) > 0) {
            $first_missing_value = true;
            $count = 1;
            foreach ($srv_grids2 AS $g_id => $srv_grid) {
                if ((string)$srv_grid['other'] != '0' && $first_missing_value == true) {
                    # dodamo spejs pred manjkajočimi vrednostmi
                    echo '<td></td>';
                    $first_missing_value = false;

                    $count++;
                }

                // Datapiping
                $srv_grid['naslov'] = Helper::dataPiping($srv_grid['naslov']);

                # izpišemo labelo grida
                echo '<td class="' . ($srv_grid['other'] == 0 ? 'category' : 'missing') . '">' . $srv_grid['naslov'] . '</td>' . "\n";				
                $count++;
            }
        }
		
		
		
        echo '        </tr>' . "\n";

        echo '</thead>';

        echo '<tbody>';

        $bg++;

        $orderby = Model::generate_order_by_field($spremenljivka, get('usr_id'));

        $srv_data_cache = array();

        $sql2 = sisplet_query("SELECT * FROM srv_data_checkgrid" . get('db_table') . " WHERE spr_id='$row[id]' AND usr_id='" . get('usr_id') . "' AND loop_id $loop_id ORDER BY grd_id");
        while ($row2 = mysqli_fetch_assoc($sql2)) {
            $srv_data_cache[$row2['vre_id']][$row2['grd_id']] = $row2;
        }

        $sql1 = sisplet_query("SELECT * FROM srv_vrednost WHERE spr_id='$row[id]' ORDER BY FIELD(vrstni_red, $orderby)");
        while ($row1 = mysqli_fetch_array($sql1)) {
            $naslov = Language::getInstance()->srv_language_vrednost($row1['id']);
            if ($naslov != '') $row1['naslov'] = $naslov;

            # preverimo izbrano vrednost
            $grid_id = $srv_data_grid[$row1['id']]['grd_id'];

            # ugotovimo ali je na katerem gridu predhodno izbran missing
            $is_missing = false;
            if (count($srv_grids1) > 0) {
                foreach ($srv_grids1 AS $i => $srv_grid) {
                    if ($srv_grid['other'] != 0) {
                        $grid_id = $srv_data_cache[$row1['id']][$i]['grd_id'];
                        if ($srv_grids1[$i]['id'] == $grid_id) {
                            $is_missing = true;
                        }
                    }
                }
            }
			
			if (count($srv_grids2) > 0) {
                foreach ($srv_grids2 AS $i => $srv_grid) {
                    if ($srv_grid['other'] != 0) {
                        $grid_id = $srv_data_cache[$row1['id']][$i]['grd_id'];
                        if ($srv_grids2[$i]['id'] == $grid_id) {
                            $is_missing = true;
                        }
                    }
                }
            }

            // Datapiping
            $row1['naslov'] = Helper::dataPiping($row1['naslov']);

            echo '        <tr id="vrednost_if_' . $row1['id'] . '" ' . (($row1['hidden'] == 1) ? 'style="display:none"' : '') . (($row1['hidden'] == 2) ? 'class="answer-disabled"' : '') . '>' . "\n";

            if ($hideLabels == false) {
                echo '          <td class="question">' . $row1['naslov'];
                if ($row1['other'] == 1) {
                    $sql3 = sisplet_query("SELECT text FROM srv_data_text" . get('db_table') . " WHERE spr_id='$spremenljivka' AND vre_id='$row1[id]' AND usr_id='" . get('usr_id') . "' AND loop_id $loop_id");
                    $row3 = mysqli_fetch_array($sql3);

                    $otherWidth = ($spremenljivkaParams->get('otherWidth') ? $spremenljivkaParams->get('otherWidth') : -1);
                    $otherHeight = ($spremenljivkaParams->get('otherHeight') ? $spremenljivkaParams->get('otherHeight') : 1);

                    if ($otherHeight > 1)
                        echo ' <textarea name="textfield_' . $row1['id'] . '" rows="' . $otherHeight . '" style="' . ($otherWidth != -1 ? ' width:' . $otherWidth . '%;' : '') . '" ' . ($is_missing ? ' disabled' : '') . '>' . ($is_missing ? '' : $row3['text']) . '</textarea>';
                    else
                        echo ' <input type="text" name="textfield_' . $row1['id'] . '" value="' . ($is_missing ? '' : $row3['text']) . '" style="' . ($otherWidth != -1 ? ' width:' . $otherWidth . '%;' : '') . '" ' . ($is_missing ? ' disabled' : '') . ' />';

                    //echo '   <input type="text" name="textfield_'.$row1['id'].'" value="'.($is_missing ? '' : $row3['text']).'" '.($is_missing ? ' disabled' : '').'>';
                }
                echo '          </td>' . "\n";
                echo '          <td></td>' . "\n";
            }

            if (count($srv_grids1) > 0) {
                $first_missing_value = true;
                $count = 1;
                foreach ($srv_grids1 AS $i => $srv_grid) {

                    $grid_id = $srv_data_cache[$row1['id']][$i]['grd_id'];

                    $value = $srv_grid['id'];

                    if ((string)$srv_grid['other'] != '0' && $first_missing_value == true) {
                        # dodamo spejs pred manjkajočimi vrednostmi
                        echo '<td></td>';
                        $first_missing_value = false;

                        $count++;
                    }
                    # izpišemo labelo grida
                    if ($srv_grid['other'] != 0) {
                        # imamo missing polje
                        echo '<td class="missing">';
                        echo '<label for="' . (($srv_grid['other'] != 0) ? 'grid_missing_value_' : 'vrednost_') . $row1['id'] . '_grid_' . $value . '">';
                        echo '<input type="checkbox" name="vrednost_' . $row1['id'] . '_grid_' . $value . '" id="' . (($srv_grid['other'] != 0) ? 'grid_missing_value_' : 'vrednost_') . $row1['id'] . '_grid_' . $value . '" value="' . $value . '"' . (($grid_id == $value && $grid_id != '') ? ' checked' : '') . ' data-calculation="0" onclick="checkChecked(this); checkBranching();">';
                        
						// Font awesome
                        echo '<span class="enka-checkbox-radio ' . (($row1['hidden'] == 2) ? ' answer-disabled' : '') . '"' .
                            ((Helper::getCustomCheckbox() != 0) ? (' style="font-size:' . Helper::getCustomCheckbox().'px;"') : '').
                            '></span>';
						
						echo '</label>';
                        echo '</td>' . "\n";
                    } else {
                        echo '<td class="category">';
                        echo '<label for="' . (($srv_grid['other'] != 0) ? 'grid_missing_value_' : 'vrednost_') . $row1['id'] . '_grid_' . $value . '">';
                        echo '<input type="checkbox" name="vrednost_' . $row1['id'] . '_grid_' . $value . '" id="' . (($srv_grid['other'] != 0) ? 'grid_missing_value_' : 'vrednost_') . $row1['id'] . '_grid_' . $value . '" value="' . $value . '"' . (($grid_id == $value && $grid_id != '' && !$is_missing) ? ' checked' : '') . ($is_missing ? ' disabled' : '') . ' data-calculation="' . $srv_grid['variable'] . '" onclick="checkChecked(this); checkBranching();">';
                        
						// Font awesome
                        echo '<span class="enka-checkbox-radio ' . (($row1['hidden'] == 2) ? ' answer-disabled' : '') . '"' .
                            ((Helper::getCustomCheckbox() != 0) ? (' style="font-size:' . Helper::getCustomCheckbox().'px;"') : '').
                            '></span>';
						
						echo '</label>';
                        echo '</td>' . "\n";
                    }

                    //vmesno polje z mejo
                    if ($count == $colspan) {
                        echo '<td></td><td class="double"></td>';
                        $first_missing_value = true;
                    }
                    $count++;
                }
            }
			
            if (count($srv_grids2) > 0) {
                $first_missing_value = true;
                $count = 1;
                foreach ($srv_grids2 AS $i => $srv_grid) {

                    $grid_id = $srv_data_cache[$row1['id']][$i]['grd_id'];

                    $value = $srv_grid['id'];

                    if ((string)$srv_grid['other'] != '0' && $first_missing_value == true) {
                        # dodamo spejs pred manjkajočimi vrednostmi
                        echo '<td></td>';
                        $first_missing_value = false;

                        $count++;
                    }
                    # izpišemo labelo grida
                    if ($srv_grid['other'] != 0) {
                        # imamo missing polje
                        echo '<td class="missing">';
                        echo '<label for="' . (($srv_grid['other'] != 0) ? 'grid_missing_value_' : 'vrednost_') . $row1['id'] . '_grid_' . $value . '">';
                        echo '<input type="checkbox" name="vrednost_' . $row1['id'] . '_grid_' . $value . '" id="' . (($srv_grid['other'] != 0) ? 'grid_missing_value_' : 'vrednost_') . $row1['id'] . '_grid_' . $value . '" value="' . $value . '"' . (($grid_id == $value && $grid_id != '') ? ' checked' : '') . ' data-calculation="0" onclick="checkChecked(this); checkBranching();">';
                        
						// Font awesome
                        echo '<span class="enka-checkbox-radio ' . (($row1['hidden'] == 2) ? ' answer-disabled' : '') . '"' .
                            ((Helper::getCustomCheckbox() != 0) ? (' style="font-size:' . Helper::getCustomCheckbox().'px;"') : '').
                            '></span>';
						
						echo '</label>';
                        echo '</td>' . "\n";
                    } else {
                        echo '<td class="category">';
                        echo '<label for="' . (($srv_grid['other'] != 0) ? 'grid_missing_value_' : 'vrednost_') . $row1['id'] . '_grid_' . $value . '">';
                        echo '<input type="checkbox" name="vrednost_' . $row1['id'] . '_grid_' . $value . '" id="' . (($srv_grid['other'] != 0) ? 'grid_missing_value_' : 'vrednost_') . $row1['id'] . '_grid_' . $value . '" value="' . $value . '"' . (($grid_id == $value && $grid_id != '' && !$is_missing) ? ' checked' : '') . ($is_missing ? ' disabled' : '') . ' data-calculation="' . $srv_grid['variable'] . '" onclick="checkChecked(this); checkBranching();">';
                        
						// Font awesome
                        echo '<span class="enka-checkbox-radio ' . (($row1['hidden'] == 2) ? ' answer-disabled' : '') . '"' .
                            ((Helper::getCustomCheckbox() != 0) ? (' style="font-size:' . Helper::getCustomCheckbox().'px;"') : '').
                            '></span>';
						
						echo '</label>';
                        echo '</td>' . "\n";
                    }
                    $count++;
                }
            }

            echo '        </tr>' . "\n";

            $bg++;
        }

        echo '</tbody>';

        echo '      </table>' . "\n";
    }

}