summaryrefslogtreecommitdiffstats
path: root/main/survey/app/Controllers/Vprasanja/VsotaController.php
blob: b69d1901cc6cb727f60e9013c6e88e5237d567e2 (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
<?php
/***************************************
 * Description: Vsota
 *
 * Vprašanje je prisotno:
 *  tip 18
 *
 * Autor: Robert Šmalc
 * Created date: 09.03.2016
 *****************************************/

namespace App\Controllers\Vprasanja;

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

class VsotaController extends Controller
{

    public function __construct()
    {
        parent::getGlobalVariables();
    }

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

    public static function getInstance()
    {

        if (self::$_instance)
            return self::$_instance;

        return new VsotaController();
    }

    public function display($spremenljivka, $oblika)
    {
        $row = Model::select_from_srv_spremenljivka($spremenljivka);

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

        $spremenljivkaParams = new enkaParameters($row['params']);
        $selected = Model::getOtherValue($spremenljivka);


        $order = Model::generate_order_by_field($spremenljivka, get('usr_id'));
        $sql1 = sisplet_query("SELECT id, naslov, if_id FROM srv_vrednost WHERE spr_id = '$spremenljivka' AND vrstni_red>0 ORDER BY FIELD(vrstni_red, $order)");

        $max = mysqli_num_rows($sql1);
        $counter = 0;
        $sum = 0;

        $spremenljivkaParams = new enkaParameters($row['params']);
        $gridWidth = (($spremenljivkaParams->get('gridWidth') > 0) ? $spremenljivkaParams->get('gridWidth') : 30);

        while ($row1 = mysqli_fetch_array($sql1)) {

            $naslov = Language::getInstance()->srv_language_vrednost($row1['id']);
            if ($naslov != '') $row1['naslov'] = $naslov;

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

            $sql2 = sisplet_query("SELECT text FROM srv_data_text" . get('db_table') . " WHERE vre_id='$row1[id]' AND usr_id='" . get('usr_id') . "' AND loop_id $loop_id");
            $row2 = mysqli_fetch_array($sql2);

            //preverjanje skritega vprasanja(-2)
            $text = isset($row2['text']) && $row2['text'] != -2 ? $row2['text'] : '';


            echo '<div class="variabla_sum width_' . $gridWidth . '" id="vrednost_if_' . $row1['id'] . '" ' . ($row1['if_id'] > 0 ? ' style="display:none"' : '') . '>';
            //echo '		<label for="spremenljivka_' . $spremenljivka . '_sestevanec_' . $counter . '">' . $row1['naslov'] . '</label>';
            //echo '		<label style="width:200px;display: inline-block;" for="spremenljivka_' . $spremenljivka . '_sestevanec_' . $counter . '">' . $row1['naslov'] . '</label>';
            echo '<label class="vsota_besedilo" for="spremenljivka_' . $spremenljivka . '_sestevanec_' . $counter . '">' . $row1['naslov'] . '</label>';
            echo '<input type="text" name="spremenljivka_' . $spremenljivka . '_vrednost_' . $row1['id'] . '" id="spremenljivka_' . $spremenljivka . '_sestevanec_' . $counter . '" value="' . $text . '" onkeypress="checkNumber(this, ' . $row['cela'] . ', ' . $row['decimalna'] . ');" onkeyup="checkNumber(this, ' . $row['cela'] . ', ' . $row['decimalna'] . '); calcSum(' . $spremenljivka . ', ' . $max . ', ' . $row['vsota_limit'] . ');" onBlur="checkBranching();" ' . ($selected ? ' disabled' : '') . '>';

            echo '</div>' . "\n";
            $counter++;
            $sum += (double)$text;
        }

        $limit = '';
        if ($row['vsota_limit'] != 0 && $row['vsota_limit'] == $row['vsota_min'])
            $limit = '(' . $row['vsota_min'] . ')';
        elseif ($row['vsota_limit'] != 0 && $row['vsota_min'] != 0)
            $limit = '(min ' . $row['vsota_min'] . ', max ' . $row['vsota_limit'] . ')';
        elseif ($row['vsota_limit'] != 0)
            $limit = '(max ' . $row['vsota_limit'] . ')';
        elseif ($row['vsota_min'] != 0)
            $limit = '(min ' . $row['vsota_min'] . ')';

        $rowl = Language::srv_language_spremenljivka($spremenljivka);
        if (isset($rowl['vsota']) && $rowl['vsota'] != '') 
            $row['vsota'] = $rowl['vsota'];
            
        if ($row['vsota'] == '') 
            $row['vsota'] = self::$lang['srv_vsota_text'];

        echo '<div class="variabla_sum width_' . $gridWidth . ' sum" id="vsota_' . $row['id'] . '">';
        echo '  <label class="vsota_besedilo" for="spremenljivka_' . $spremenljivka . '_vsota">' . $row['vsota'] . '</label>';
        echo '  <input type="text" name="spremenljivka_' . $spremenljivka . '_vsota_' . $row['id'] . '" id="spremenljivka_' . $spremenljivka . '_vsota" value="' . $sum . '" disabled class="def">';
        echo '</div>' . "\n";

        if ($row['vsota_show'] == 1)
            echo ' 		<label class="limit_vsota">' . $limit . '</label>';

    }
}