From 19985dbb8c0aa66dc4bf7905abc1148de909097d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20Luka=20=C5=A0ijanec?= Date: Tue, 11 Jan 2022 12:35:47 +0100 Subject: prvi-commit --- .../Controllers/Vprasanja/MultigridController.php | 1686 ++++++++++++++++++++ 1 file changed, 1686 insertions(+) create mode 100644 main/survey/app/Controllers/Vprasanja/MultigridController.php (limited to 'main/survey/app/Controllers/Vprasanja/MultigridController.php') diff --git a/main/survey/app/Controllers/Vprasanja/MultigridController.php b/main/survey/app/Controllers/Vprasanja/MultigridController.php new file mode 100644 index 0000000..85fd49d --- /dev/null +++ b/main/survey/app/Controllers/Vprasanja/MultigridController.php @@ -0,0 +1,1686 @@ +displayMultigrid($spremenljivka); + */ + public function display($spremenljivka) + { + global $lang; + + $loop_id = get('loop_id') == null ? " IS NULL" : " = '" . get('loop_id') . "'"; + + // Pri vpogledu moramo skriti name atribut pri loopih, 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']); + + // prej: + // $gridWidth = (($spremenljivkaParams->get('gridWidth') > 0) ? $spremenljivkaParams->get('gridWidth') : 30); + // tole prej je klicalo funkcijo 2x. Ker imam še opcijo -2, bom naredil z enim klicem in več kode tu. + $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; + } + + $gridAlign = (($spremenljivkaParams->get('gridAlign') > 0) ? $spremenljivkaParams->get('gridAlign') : 0); + $cssAlign = ''; + if ($gridAlign == 1) + $cssAlign = ' alignLeft'; + elseif ($gridAlign == 2) + $cssAlign = ' alignRight'; + + + // Za izris traku + $diferencial_trak = ($spremenljivkaParams->get('diferencial_trak') ? $spremenljivkaParams->get('diferencial_trak') : 0); //za checkbox trak + $trak_num_of_titles = ($spremenljivkaParams->get('trak_num_of_titles') ? $spremenljivkaParams->get('trak_num_of_titles') : 0); //belezi stevilo nadnaslovov + if($diferencial_trak == 1 && ($row['enota'] == 1 || $row['enota'] == 0)){ //ce je trak vklopljen @ diferencial ali klasicna tabela + $trak_class = 'trak_class'; + $trak_class_input = 'trak_class_input'; + $question = 'question_trak'; + + if ($row['enota'] == 1){ //ce je diferencial + $gridWidth = 15; //za sirino celic skrajno levo pa desno od traku + } + + if($trak_num_of_titles != 0){ + $display_trak_num_of_titles = 'style="display:none;"'; + $trak_nadnaslov_table_td_width = 100 / $trak_num_of_titles; //spremenljivka za razporeditev sirine nadnaslovov @ traku + } + + $display_trak_num_of_titles = ''; + } + else{ + $trak_class = ''; + $trak_class_input = ''; + $question = 'question'; + $display_trak_num_of_titles = 'style="display:none;"'; + } + + for($i = 1; $i <= $trak_num_of_titles; $i++){ + $trak_nadnaslov[$i] = ($spremenljivkaParams->get('trak_nadnaslov_'.$i.'') ? $spremenljivkaParams->get('trak_nadnaslov_'.$i.'') : $lang['srv_new_text']); + } + // Za izris traku - konec + + + // izracuni za sirino celic + $size = $row['grids']; + + # polovimo vrednosti gridov, prevedemo 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]' ORDER BY vrstni_red"); + + 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++; + } + } + + # če imamo mankajoče potem dodamo še en prazen stolpec za razmak + if ($mv_count > 0) { + $size += 1 + $mv_count; + } + // diferencial + if ($row['enota'] == 1) { + $size += 2; + } + + # č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; + + + // IZRIS TABELE + echo '' . "\n"; + + + // Colgroup + // ce je gridWidth enak nula, imamo skrito labelo. + // hideLabels bom posredoval naprej v funkcije + if ($hideLabels == false) { + echo ''; + echo ' '; + echo ''; + + echo ''; + echo ' '; + echo ''; + } + + + + echo ''; + for ($i = 1; $i <= $row['grids']; $i++) { + echo ''; + } + echo ''; + + + if ($mv_count > 0) { + echo ''; + echo ' '; + echo ''; + + echo ''; + for ($i = 1; $i <= $mv_count; $i++) + echo ''; + echo ''; + } + if ($row['enota'] > 0 && !in_array($row['enota'], [11,12])) { + // desnih label ne bom skrival, ker je neumno dati dvojne labele + skrite labele! + echo ''; + echo ' '; + echo ''; + + echo ''; + echo ' '; + echo ''; + } + // Colgroup - konec + + + // Header vrstica + echo ''; + $this->displayMultigridHeader($spremenljivka, $row, $srv_grids, $mv_count, $cssAlign, $diferencial_trak, $trak_nadnaslov, $display_trak_num_of_titles, $middle_row=false, $hideLabels); + echo ''; + + + // Body tabele + echo ''; + + $bg++; + + $orderby = Model::generate_order_by_field($spremenljivka, get('usr_id')); + + # cache tabele srv_data_grid, da se ne dela vsakic posebej nov query (preberemo enkrat vse odgovore userja) + $srv_data_grid = array(); + $sql_grid = sisplet_query("SELECT * FROM srv_data_grid" . get('db_table') . " WHERE spr_id='$row[id]' AND usr_id='" . get('usr_id') . "' AND loop_id $loop_id"); + while ($row_grid = mysqli_fetch_array($sql_grid)) { + $srv_data_grid[$row_grid['vre_id']] = $row_grid; + } + + // Ali skrivamo radio gumbe in checkboxe + $presetValue = ($spremenljivkaParams->get('presetValue') > 0 && empty($srv_data_grid)) ? $spremenljivkaParams->get('presetValue') : 0; + + # loop skozi srv_vrednost, da izpišemo vrstice z vrednostmi + $sql1 = sisplet_query("SELECT id, naslov, naslov2, hidden, other 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; + } + + # po potrebi prevedemo naslov2 za semanticni diferencial + if($row['enota'] == 1){ + $naslov2 = Language::getInstance()->srv_language_vrednost($row1['id'], true); + if ($naslov2 != '') { + $row1['naslov2'] = $naslov2; + } + } + + # 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_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 ' ' . "\n"; + + if ($hideLabels == false) { + + echo ' ' . "\n"; + echo ' ' . "\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 ' ' . "\n"; + $first_missing_value = false; + } + + $value = $srv_grids[$i]['id']; + + # izpišemo radio grida + if ($srv_grid['other'] != 0) { + echo '' . "\n"; + } + else { + if($diferencial_trak == 1 && ($row['enota'] == 1 || $row['enota'] == 0) ){ + echo '' . "\n"; + } + else{ + // Pri VAS in slikovnem tiput mora biti 'checked' označen tudi pri TD elementu + $_checked = (((($grid_id == $value && $grid_id != '') || ($presetValue == $value && $presetValue != 0)) && !$is_missing) ? ' checked' : ''); + + // V kolikor imamo vizalno skalo in smeške + if($row['enota'] == 11){ + $tabelaSmeski = 'visual-radio-scale visual-radio-table'; + } + elseif($row['enota'] == 12){ + $tabelaSmeski = 'custom_radio_picture custom-radio-table'; + } + else{ + $tabelaSmeski =''; + } + + echo '' . "\n"; + } + } + } + } + # dodamo še enoto + if ($row['enota'] == 1) { + // Datapiping + $row1['naslov2'] = Helper::dataPiping($row1['naslov2']); + + echo ' ' . "\n"; + echo ' ' . "\n"; + } + echo ' ' . "\n"; + + $bg++; + } + + echo ''; + + echo '
' . "\n"; + + + // za ureditev prilagajanja label stolpcev - prilagajanje trem opisnim nadnaslovom + $custom_column_label_option = ($spremenljivkaParams->get('custom_column_label_option') ? $spremenljivkaParams->get('custom_column_label_option') : 1); + echo ''; + + // prilagajanje stevilu izbranih nadnaslovov + if($trak_num_of_titles != 0){ + ?> + + get('grid_repeat_header') ? $spremenljivkaParams->get('grid_repeat_header') : 0); + if($grid_repeat_header > 0){ + echo ''; + } + } + + /************************************************ + * Stara funkcija $this->displayMultigridDropdown($spremenljivka); + ************************************************/ + public function dropdown($spremenljivka) + { + global $lang; + + $loop_id = get('loop_id') == null ? " IS NULL" : " = '" . get('loop_id') . "'"; + + $row = Model::select_from_srv_spremenljivka($spremenljivka); + + $_otherStatusFields = array(99 => 'undecided', 98 => 'rejected', 97 => 'inappropriate'); + + $spremenljivkaParams = new enkaParameters($row['params']); + // $gridWidth = (($spremenljivkaParams->get('gridWidth') > 0) ? $spremenljivkaParams->get('gridWidth') : 30); + // tole prej je klicalo funkcijo 2x. Ker imam še opcijo -2, bom naredil z enim klicem in več kode tu. + $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; + } + $gridAlign = (($spremenljivkaParams->get('gridAlign') > 0) ? $spremenljivkaParams->get('gridAlign') : 0); + if ($gridAlign == 0) + $cssAlign = ' class="alignCenter"'; + elseif ($gridAlign == 1) + $cssAlign = ' class="alignLeft"'; + elseif ($gridAlign == 2) + $cssAlign = ' class="alignRight"'; + + echo ' ' . "\n"; + if ($hideLabels == false) { + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + } + echo ''; + echo ''; + echo ''; + + echo ''; + + $bg++; + + $orderby = Model::generate_order_by_field($spremenljivka, get('usr_id')); + + // cache tabele srv_grid, da se ne bere vsakic znova + $srv_grids = array(); + + $sql_grid = sisplet_query("SELECT * FROM srv_grid WHERE spr_id = '$row[id]'"); + while ($row_grid = mysqli_fetch_array($sql_grid)) { + + $naslov = Language::srv_language_grid($row['id'], $row_grid['id']); + if ($naslov != '') $row_grid['naslov'] = $naslov; + + $srv_grids[$row_grid['vrstni_red']] = $row_grid; + } + + // cache tabele srv_data_grid, da se ne dela vsakic posebej nov query (preberemo enkrat vse odgovore userja) + $srv_data_grid = array(); + $sql_grid = sisplet_query("SELECT * FROM srv_data_grid" . get('db_table') . " WHERE spr_id='$row[id]' AND usr_id='" . get('usr_id') . "' AND loop_id $loop_id"); + while ($row_grid = mysqli_fetch_array($sql_grid)) { + $srv_data_grid[$row_grid['vre_id']] = $row_grid; + } + + $sql1 = sisplet_query("SELECT id, naslov, hidden, other 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; + + // Datapiping + $row1['naslov'] = Helper::dataPiping($row1['naslov']); + + echo '' . "\n"; + + if ($hideLabels == false) { + echo '' . "\n"; + echo ' ' . "\n"; + } + + + $grid_id = $srv_data_grid[$row1['id']]['grd_id']; + + echo '' . "\n"; + + echo '' . "\n"; + + $bg++; + } + + echo ''; + + 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 ' '; + else + echo ' '; + + //echo ' '; + } + echo ' '; + + + if ($row['enota'] == 2) { + $spremenljivkaParams = new enkaParameters($row['params']); + $prvaVrstica_roleta = ($spremenljivkaParams->get('prvaVrstica_roleta') ? $spremenljivkaParams->get('prvaVrstica_roleta') : 1); + + //echo '' . "\n"; + switch ($prvaVrstica_roleta) { + case "1": + echo ' '; + break; + case "2": + + break; + case "3": + echo ' '; + break; + } + } + + if (count($srv_grids) > 0) { + foreach ($srv_grids AS $i => $srv_grid) { + + $row5 = $srv_grid; + + $value = $srv_grid['id']; + $vsebina = ''; + + echo ''; + } + } + + + echo '' . "\n"; + echo '
' . "\n"; + } + + /************************************************ + * Stara funkcija $this->displayMultigridSelectBox($spremenljivka);d + ************************************************/ + public function selectBox($spremenljivka) + { + global $lang; + + $loop_id = get('loop_id') == null ? " IS NULL" : " = '" . get('loop_id') . "'"; + + $row = Model::select_from_srv_spremenljivka($spremenljivka); + + $_otherStatusFields = array(99 => 'undecided', 98 => 'rejected', 97 => 'inappropriate'); + + $spremenljivkaParams = new enkaParameters($row['params']); + // $gridWidth = (($spremenljivkaParams->get('gridWidth') > 0) ? $spremenljivkaParams->get('gridWidth') : 30); + + // tole prej je klicalo funkcijo 2x. Ker imam še opcijo -2, bom naredil z enim klicem in več kode tu. + $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; + } + $gridAlign = (($spremenljivkaParams->get('gridAlign') > 0) ? $spremenljivkaParams->get('gridAlign') : 0); + + if ($gridAlign == 0) + $cssAlign = ' class="alignCenter"'; + elseif ($gridAlign == 1) + $cssAlign = ' class="alignLeft"'; + elseif ($gridAlign == 2) + $cssAlign = ' class="alignRight"'; + + echo ' ' . "\n"; + + if ($hideLabels ==false) { + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + } + echo ''; + echo ''; + echo ''; + + echo ''; + + $bg++; + + $orderby = Model::generate_order_by_field($spremenljivka, get('usr_id')); + + $missingi = array(); + + // cache tabele srv_grid, da se ne bere vsakic znova + $srv_grid = array(); + $sql_grid = sisplet_query("SELECT * FROM srv_grid WHERE spr_id = '$row[id]'"); + while ($row_grid = mysqli_fetch_array($sql_grid)) { + + $naslov = Language::srv_language_grid($row['id'], $row_grid['id']); + if ($naslov != '') $row_grid['naslov'] = $naslov; + + $srv_grid[$row_grid['vrstni_red']] = $row_grid; + + //belezenje missingov + if($row_grid['other']!=0){ + array_push($missingi, $row_grid['naslov']); + } + } + + // cache tabele srv_data_grid, da se ne dela vsakic posebej nov query (preberemo enkrat vse odgovore userja) + $srv_data_grid = array(); + $sql_grid = sisplet_query("SELECT * FROM srv_data_grid" . get('db_table') . " WHERE spr_id='$row[id]' AND usr_id='" . get('usr_id') . "' AND loop_id $loop_id"); + while ($row_grid = mysqli_fetch_array($sql_grid)) { + $srv_data_grid[$row_grid['vre_id']] = $row_grid; + } + + $sql1 = sisplet_query("SELECT id, naslov, hidden, other 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; + + // Datapiping + $row1['naslov'] = Helper::dataPiping($row1['naslov']); + + echo '' . "\n"; + + if ($hideLabels == false) { + echo '' . "\n"; + echo ' ' . "\n"; + } + + + $grid_id = $srv_data_grid[$row1['id']]['grd_id']; + + echo '' . "\n"; + + echo '' . "\n"; + + $bg++; + } + + echo ''; + + 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 ' '; + else + echo ' '; + + //echo ' '; + } + echo ' '; + + // todo id se podvaja - popravljeno + //echo ''."\n"; + echo '' . "\n"; + switch ($prvaVrstica) { + case "1": + + break; + case "2": + echo ' '; + break; + case "3": + echo ' '; + break; + } + + } + + //echo ''."\n"; + + //for ($i = 1; $i <= $row['grids']; $i++) { + for ($i = 1; $i <= count($srv_grid); $i++) { + + $row5 = $srv_grid[$i]; + $value1 = $value2 = $row5['id']; + + if($row5['other']!=0){ //ce so missingi + $value2 = $row5['other']; + } + + // todo name je obsolete - popravljeno + if ($row['tip'] == 16) { + //echo ''; + echo ''; + //echo ''; + } else { + //echo ''; + echo ''; + } + } + + echo '' . "\n"; + echo '
' . "\n"; + } + + /************************************************ + * Stara funkcija $this->displayMultigridSelectBox($spremenljivka); + ************************************************/ + public function checkbox($spremenljivka) + { + global $lang; + + $row = Model::select_from_srv_spremenljivka($spremenljivka); + + $loop_id = get('loop_id') == null ? " IS NULL" : " = '" . get('loop_id') . "'"; + + // izracuni za sirino celic + $size = $row['grids']; + + $spremenljivkaParams = new enkaParameters($row['params']); + + // za združljivost za nazaj dodam tudi v "staro funkcijo" opcijo prikaza brez labele :) + // $gridWidth = (($spremenljivkaParams->get('gridWidth') > 0) ? $spremenljivkaParams->get('gridWidth') : 30); + // tole prej je klicalo funkcijo 2x. Ker imam še opcijo -2, bom naredil z enim klicem in več kode tu. + $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; + } + $gridAlign = (($spremenljivkaParams->get('gridAlign') > 0) ? $spremenljivkaParams->get('gridAlign') : 0); + $cssAlign = ''; + if ($gridAlign == 1) + $cssAlign = ' alignLeft'; + elseif ($gridAlign == 2) + $cssAlign = ' alignRight'; + + // 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]' ORDER BY vrstni_red"); + 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++; + } + } + + echo ' ' . "\n"; + + if ($hideLabels == false) { + echo ''; + echo ' '; + echo ''; + + echo ''; + echo ' '; + echo ''; + } + + echo ''; + for ($i = 1; $i <= $row['grids']; $i++) + echo ''; + echo ''; + + if ($mv_count > 0) { + echo ''; + echo ' '; + echo ''; + + echo ''; + for ($i = 1; $i <= $mv_count; $i++) + echo ''; + echo ''; + } + + + # č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; + + + // Header tabele + echo ''; + $this->displayMulticheckboxHeader($spremenljivka, $row, $srv_grids, $mv_count, $cssAlign, $middle_row=false, $hideLabels); + echo ''; + + + // Body tabele + echo ''; + + $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"); + if (!$sql2) echo mysqli_error($GLOBALS['connect_db']); + while ($row2 = mysqli_fetch_assoc($sql2)) { + $srv_data_cache[$row2['vre_id']][$row2['grd_id']] = $row2; + } + + $sql1 = sisplet_query("SELECT id, naslov, hidden, other 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_grids) > 0) { + foreach ($srv_grids AS $i => $srv_grid) { + if ($srv_grid['other'] != 0) { + $grid_id = $srv_data_cache[$row1['id']][$i]['grd_id']; + if ($srv_grids[$i]['id'] == $grid_id) { + $is_missing = true; + } + } + } + } + + // Datapiping + $row1['naslov'] = Helper::dataPiping($row1['naslov']); + + echo ' ' . "\n"; + + if ($hideLabels == false) { + echo ' ' . "\n"; + echo ' ' . "\n"; + } + + if (count($srv_grids) > 0) { + $first_missing_value = true; + foreach ($srv_grids AS $i => $srv_grid) { + + $grid_id = $srv_data_cache[$row1['id']][$i]['grd_id']; + + $value = $srv_grid['id']; + $vsebina = ''; + + if ((string)$srv_grid['other'] != '0' && $first_missing_value == true) { + # dodamo spejs pred manjkajočimi vrednostmi + echo ''; + $first_missing_value = false; + } + + # izpišemo labelo grida + if ($srv_grid['other'] != 0) { + echo '' . "\n"; + } else {# ni missing vrednost + echo '' . "\n"; + } + + } + } + + echo ' ' . "\n"; + + $bg++; + } + echo ''; + + 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 ' '; + else + echo ' '; + } + echo ' '; + # imamo missing polje + echo ''; + echo ''; + echo ''; + echo '
' . "\n"; + + // JS za ponvaljanje naslovne vrstice + $grid_repeat_header = ($spremenljivkaParams->get('grid_repeat_header') ? $spremenljivkaParams->get('grid_repeat_header') : 0); + if($grid_repeat_header > 0){ + echo ''; + } + } + + + /** + * @desc prikaze vnosno polje za multiple (kombinirano) tabelo, ki je sestavljena iz večih tabel + * Stara funkcija $this->displayMultigridMultiple($spremenljivka); + */ + public function multiple($spremenljivka) + { + global $admin_type; + global $lang; + + $loop_id = get('loop_id') == null ? " IS NULL" : " = '" . get('loop_id') . "'"; + + // Pri vpogledu moramo skriti name atribut pri loopih, da se izpise prava vrednost + $hideName = ((get('loop_id') != null) && ($_GET['m'] == 'quick_edit')) ? true : false; + + $row = Model::select_from_srv_spremenljivka($spremenljivka); + + + $sql1 = sisplet_query("SELECT spr_id FROM srv_grid_multiple WHERE parent='$spremenljivka' ORDER BY vrstni_red"); + while ($row1 = mysqli_fetch_array($sql1)) { + $multiple[] = $row1['spr_id']; + } + if (count($multiple) == 0) + return; + + $spremenljivkaParams = new enkaParameters($row['params']); + // $gridWidth = (($spremenljivkaParams->get('gridWidth') > 0) ? $spremenljivkaParams->get('gridWidth') : 30); + + // tole prej je klicalo funkcijo 2x. Ker imam še opcijo -2, bom naredil z enim klicem in več kode tu. + $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; + } + $gridAlign = (($spremenljivkaParams->get('gridAlign') > 0) ? $spremenljivkaParams->get('gridAlign') : 0); + + $cssAlign = ''; + if ($gridAlign == 1) + $cssAlign = ' alignLeft'; + elseif ($gridAlign == 2) + $cssAlign = ' alignRight'; + + // izracuni za sirino celic + $size = $row['grids']; + + # polovimo vrednosti gridov, prevedemo 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 g.*, s.tip, s.enota, s.dostop, s.params FROM srv_grid g, srv_grid_multiple m, srv_spremenljivka s WHERE s.id=g.spr_id AND g.spr_id=m.spr_id AND m.spr_id IN (" . implode(',', $multiple) . ") ORDER BY m.vrstni_red, g.vrstni_red"); + if (!$sql_grid) echo mysqli_error($GLOBALS['connect_db']); + + while ($row_grid = mysqli_fetch_assoc($sql_grid)) { + + # priredimo naslov če prevajamo anketo + $naslov = Language::srv_language_grid($row_grid['spr_id'], $row_grid['id']); + if ($naslov != '') { + $row_grid['naslov'] = $naslov; + } + + // Sirina posamezne podtabele v % (lahko jo posebej nastavimo) + $subtabelaParams = new enkaParameters($row_grid['params']); + $gridmultiple_width = (($subtabelaParams->get('gridmultiple_width') > 0) ? $subtabelaParams->get('gridmultiple_width') : 0); + if($gridmultiple_width > 0){ + + $sql_grid_size = sisplet_query("SELECT COUNT(*) as cnt_grids FROM srv_grid WHERE spr_id='".$row_grid['spr_id']."'"); + $row_grid_size = mysqli_fetch_assoc($sql_grid_size); + + if((int)$row_grid_size['cnt_grids'] > 1){ + $row_grid['gridmultiple_width'] = floor($gridmultiple_width / $row_grid_size['cnt_grids']); + } + else{ + $row_grid['gridmultiple_width'] = $gridmultiple_width; + } + } + + if ($row_grid['tip'] == 6 && ($row_grid['enota'] == 2 || $row_grid['enota'] == 6)) { + $srv_grids[$row_grid['spr_id'] . '-0'] = $row_grid; + } + elseif ($row_grid['tip'] == 16 && $row_grid['enota'] == 6) { + $srv_grids[$row_grid['spr_id'] . '-0'] = $row_grid; + } + else { + $srv_grids[$row_grid['spr_id'] . '-' . $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++; + } + } + } + + $size = count($srv_grids); + + + # č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 '' . "\n"; + + if ($hideLabels == false) { + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + } + + echo ''; + /*for ($i = 1; $i <= $size; $i++) + echo '';*/ + foreach ($srv_grids as $grid){ + if($grid['gridmultiple_width'] > 0) + echo ''; + else + echo ''; + } + echo ''; + + echo ''; + + // podnaslovi gridov + if ($row['grid_subtitle1'] == '1') { + echo ' '; + if ($hideLabels == false) { + echo ' '; + //echo ' '; + echo ' '; + } + $sql2 = sisplet_query("SELECT s.id, s.naslov, s.tip, s.dostop, s.enota, s.grids FROM srv_spremenljivka s, srv_grid_multiple m WHERE s.id = m.spr_id AND parent = '" . $row['id'] . "' ORDER BY m.vrstni_red"); + while ($row2 = mysqli_fetch_array($sql2)) { + + // Datapiping + $row2['naslov'] = Helper::dataPiping($row2['naslov']); + + if (($admin_type <= $row2['dostop'] && $admin_type >= 0) || ($admin_type == -1 && $row2['dostop'] == 4) || get('forceShowSpremenljivka')){ + if (get('lang_id') != null) { + $rowl = \App\Controllers\LanguageController::srv_language_spremenljivka($row2['id']); + if (strip_tags($rowl['naslov']) != '') $row2['naslov'] = $rowl['naslov']; + } + + echo ' '; + } + } + + echo ' '; + } + + echo ' ' . "\n"; + if ($hideLabels == false) { + echo ' ' . "\n"; + echo ' ' . "\n"; + } + + # Izpišemo TOP vrstico z labelami + if (count($srv_grids) > 0) { + $first_missing_value = true; + $jj = 0; + foreach ($srv_grids AS $i => $srv_grid) { + $jj++; + if (($admin_type <= $srv_grid['dostop'] && $admin_type >= 0) || ($admin_type == -1 && $srv_grid['dostop'] == 4) || get('forceShowSpremenljivka')) { + + // Datapiping + $srv_grid['naslov'] = Helper::dataPiping($srv_grid['naslov']); + + if ((string)$srv_grid['other'] != '0' && $first_missing_value == true) { + # dodamo spejs pred manjkajočimi vrednostmi + echo ' ' . "\n"; + $first_missing_value = false; + } + + # izpišemo labelo grida + if ($srv_grid['tip'] == 6 && ($srv_grid['enota'] == 2 || $srv_grid['enota'] == 6)) { + echo ''; + } + elseif ($srv_grid['tip'] == 16 && $srv_grid['enota'] == 6) { + echo ''; + } + else { + echo '' . "\n"; + } + } + } + } + if ($row['enota'] > 0) echo ''; // differencial + echo ' ' . "\n"; + echo ''; + + echo ''; + + $bg++; + + $orderby = Model::generate_order_by_field($multiple[0], get('usr_id')); + + # cache tabele srv_data_grid, da se ne dela vsakic posebej nov query (preberemo enkrat vse odgovore userja) + $srv_data_grid = array(); + $sql_grid = sisplet_query("SELECT * FROM srv_data_grid" . get('db_table') . " WHERE spr_id IN (" . implode(',', $multiple) . ") AND usr_id='" . get('usr_id') . "' AND loop_id $loop_id"); + while ($row_grid = mysqli_fetch_array($sql_grid)) { + $srv_data_grid[$row_grid['spr_id']][$row_grid['vre_id']] = $row_grid; + } + + $srv_data_checkgrid = array(); + $sql2 = sisplet_query("SELECT * FROM srv_data_checkgrid" . get('db_table') . " WHERE spr_id IN (" . implode(',', $multiple) . ") AND usr_id='" . get('usr_id') . "' AND loop_id $loop_id ORDER BY grd_id"); + if (!$sql2) echo mysqli_error($GLOBALS['connect_db']); + while ($row2 = mysqli_fetch_assoc($sql2)) { + $srv_data_checkgrid[$row2['spr_id']][$row2['vre_id']][$row2['grd_id']] = $row2; + } + + $srv_data_cache = array(); + $sql2 = sisplet_query("SELECT * FROM srv_data_textgrid" . get('db_table') . " WHERE spr_id IN (" . implode(',', $multiple) . ") 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['spr_id']][$row2['vre_id']][$row2['grd_id']] = $row2; + } + + # loop skozi srv_vrednost, da izpišemo vrstice z vrednostmi + $sql1 = sisplet_query("SELECT id, naslov, naslov2, vrstni_red, hidden, other FROM srv_vrednost WHERE spr_id='" . $multiple[0] . "' ORDER BY FIELD(vrstni_red, $orderby)"); + $sql_if_variabla = sisplet_query("SELECT id, other FROM srv_vrednost WHERE spr_id='" . $row['id'] . "' ORDER BY FIELD(vrstni_red, $orderby)"); + while ($row1 = mysqli_fetch_array($sql1)) { + + $row_if_variabla = mysqli_fetch_array($sql_if_variabla); + + # po potrebi prevedemo naslov + $naslov = Language::getInstance()->srv_language_vrednost($row_if_variabla['id']); + if ($naslov != '') { + $row1['naslov'] = $naslov; + } + + // Datapiping + $row1['naslov'] = Helper::dataPiping($row1['naslov']); + + $is_missing = false; + + echo ' ' . "\n"; + + //echo ' '."\n"; + + if ($hideLabels == false) { + echo ' ' . "\n"; + echo ' ' . "\n"; + } + if (count($srv_grids) > 0) { + $first_missing_value = true; + + $jj = 0; + + foreach ($srv_grids AS $i => $srv_grid) { + $jj++; + + if (($admin_type <= $srv_grid['dostop'] && $admin_type >= 0) || ($admin_type == -1 && $srv_grid['dostop'] == 4) || get('forceShowSpremenljivka')) { + + $sql2 = sisplet_query("SELECT id FROM srv_vrednost WHERE spr_id='" . $srv_grid['spr_id'] . "' AND vrstni_red = '" . $row1['vrstni_red'] . "'"); + $row2 = mysqli_fetch_array($sql2); + + $row_spr = Model::select_from_srv_spremenljivka($srv_grid['spr_id']); + $spr_Params = new enkaParameters($row_spr['params']); + + $value = $srv_grids[$i]['id']; + + // multigrid + if ($row_spr['tip'] == 6) { + + // dropdown in selectbox + if (($row_spr['enota'] == 2) || ($row_spr['enota'] == 6)) { + $sbSize = ($spr_Params->get('sbSize') ? $spr_Params->get('sbSize') : 3); + $prvaVrstica = ($spr_Params->get('prvaVrstica') ? $spr_Params->get('prvaVrstica') : 1); + $prvaVrstica_roleta = ($spr_Params->get('prvaVrstica_roleta') ? $spr_Params->get('prvaVrstica_roleta') : 1); + $grid_id = $srv_data_grid[$row_spr['id']][$row2['id']]['grd_id']; + + echo ''; + } else { + + $grid_id = $srv_data_grid[$row_spr['id']][$row2['id']]['grd_id']; + + echo '' . "\n"; + + } + + // multi + } elseif ($row_spr['tip'] == 16) { + + //multi selectbox + if ($row_spr['enota'] == 6) { + $spremenljivkaParams = new enkaParameters($row_spr['params']); + $sbSize = ($spremenljivkaParams->get('sbSize') ? $spremenljivkaParams->get('sbSize') : 3); + $prvaVrstica = ($spremenljivkaParams->get('prvaVrstica') ? $spremenljivkaParams->get('prvaVrstica') : 1); + if ($prvaVrstica != 1) { + $sbSize = $sbSize + 1; + } + $grid_id = $srv_data_grid[$row_spr['id']][$row2['id']]['grd_id']; + + echo ''; + }//multi checkbox + elseif ($row_spr['enota'] != 6) { + $grid_id = $srv_data_checkgrid[$row_spr['id']][$row2['id']][$value]['grd_id']; + + echo '' . "\n"; + } + // multitext + } elseif ($row_spr['tip'] == 19) { + + $taWidth = ($spr_Params->get('taWidth') ? $spr_Params->get('taWidth') : -1); + $taHeight = ($spr_Params->get('taHeight') ? $spr_Params->get('taHeight') : 1); + + //default sirina + if ($taWidth == -1) { + $taWidth = 80; + } + else { + $taWidth = $taWidth * 10; // da dobimo % (opcije se od 1 - 9) + } + + $vsebina = $srv_data_cache[$row_spr['id']][$row2['id']][$srv_grid['id']]['text']; + + // datum + if ($spr_Params->get('multigrid-datum') == '1') { + + echo '' . "\n"; + } + + // multinumber + } elseif ($row_spr['tip'] == 20) { + + $taWidth = ($spr_Params->get('taWidth') ? $spr_Params->get('taWidth') : -1); + $taHeight = ($spr_Params->get('taHeight') ? $spr_Params->get('taHeight') : 1); + + //default sirina + if ($taWidth == -1) { + $taWidth = 80; + } + else { + $taWidth = $taWidth * 10; // da dobimo % (opcije se od 1 - 9) + } + + $vsebina = $srv_data_cache[$row_spr['id']][$row2['id']][$srv_grid['id']]['text']; + + + echo '' . "\n"; + + } + } + } + } + # dodamo še enoto + if ($row['enota'] == 1) { + echo ' ' . "\n"; + echo ' ' . "\n"; + } + echo ' ' . "\n"; + + $bg++; + } + + echo ''; + + echo '
' . $row2['naslov'] . '
' . $srv_grid['naslov'] . '
'; + echo $row1['naslov']; + if ($row_if_variabla['other'] == 1) { + $sql3 = sisplet_query("SELECT text FROM srv_data_text" . get('db_table') . " WHERE spr_id='" . $multiple[0] . "' 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 ' '; + else + echo ' '; + + //echo ' '; + } + echo ''; + if ($row_spr['enota'] == 2) {//roleta + echo ''; + + switch ($prvaVrstica) { + case "1": + + break; + case "2": + echo ''; + break; + case "3": + echo ''; + break; + } + + + //echo ''; + } + + + $sql_grid = sisplet_query("SELECT id, naslov, variable FROM srv_grid WHERE spr_id='$row_spr[id]' ORDER BY vrstni_red"); + while ($row_grid = mysqli_fetch_array($sql_grid)) { + echo ''; + } + echo ''; + echo ''; + # ni missing vrednost + echo ''; + echo ''; + + //echo ''; + + switch ($prvaVrstica) { + case "1": + + break; + case "2": + echo ''; + break; + case "3": + echo ''; + break; + } + + + //echo ''; + + $sql_grid = sisplet_query("SELECT id, naslov, variable FROM srv_grid WHERE spr_id='$row_spr[id]' ORDER BY vrstni_red"); + while ($row_grid = mysqli_fetch_array($sql_grid)) { + echo ''; + //echo ''; + } + echo ''; + echo ''; + echo ''; + echo ''; + echo '' . ''; + + $date_element = "#multi_" . $row_spr['id'] . "_" . $row2['id'] . "_grid_" . $value; + ?> + + ' . "\n"; + } + // navaden text + else { + echo ''; + echo ''; + echo ''; + //echo ''; + echo ''; + + echo '' . $row1['naslov2'] . '
' . "\n"; + } + + + // Izris naslovne vrstice tabele za radio tabelo + private function displayMultigridHeader($spremenljivka, $row, $srv_grids, $mv_count, $cssAlign, $diferencial_trak, $trak_nadnaslov, $display_trak_num_of_titles, $middle_row=false, $hideLabels=false){ + global $lang; + + // Vrstica z nadnaslovi + echo ''; + + if ($hideLabels == false) { + echo ' '; + echo ' '; + } + + for ($j = 1; $j <= $row['grids']; $j++) { + + if($j == 1){ + $nadnaslov_floating = 'left'; + } + else if($j == $row['grids']){ + $nadnaslov_floating = 'right'; + } + else{ + $nadnaslov_floating = 'none'; + } + + echo '
lang_id!=null ?' default="1"':'').'>' . $trak_nadnaslov[$j] . '
'; + } + + // Ce je diferencial + if ($row['enota'] == 1) { + + echo ''; + + if($mv_count > 0 && $diferencial_trak == 1){ + for($z=0; $z<=$mv_count; $z++){ + echo ''; + } + } + } + echo ''; + // Vrstica z nadnaslovi - konec + + + // Preverimo, ce ponavljamo glavo - potem ji dodamo class in jo z JS ponovimo + $spremenljivkaParams = new enkaParameters($row['params']); + $grid_repeat_header = ($spremenljivkaParams->get('grid_repeat_header') ? $spremenljivkaParams->get('grid_repeat_header') : 0); + + // Zacetek TR + if (($mv_count > 0 && $diferencial_trak == 1) || $diferencial_trak != 1) { + echo ' 0 ? 'repeat_header' : '').'">' . "\n"; + if ($hideLabels == false) { + echo ' '; + echo ' '; + } + } + + if (count($srv_grids) > 0) { + + $first_missing_value = true; + + foreach ($srv_grids AS $i => $srv_grid) { + + # dodamo spejs pred manjkajočimi vrednostmi + if ((string)$srv_grid['other'] != '0' && $first_missing_value == true) { + echo ' ' . "\n"; + $first_missing_value = false; + } + + // Datapiping + $srv_grid['naslov'] = Helper::dataPiping($srv_grid['naslov']); + + // Ce ni traku izpišemo labelo grida + if($diferencial_trak != 1){ + echo ' ' . $srv_grid['naslov'] . '' . "\n"; + } + // Ce je trak + elseif($diferencial_trak == 1 && $mv_count > 0){ + + // Izpišemo ustrezno labelo grida + if($srv_grid['other'] == 0){ //ce je labela za kategorijo odgovora, naj bo prazno + echo ' ' . "\n"; + } + // Drugace, ce je labela za missing, izpisi labelo + else { + echo ' ' . $srv_grid['naslov'] . '' . "\n"; + } + } + } + } + + // Differencial in ni traku + if ($row['enota'] > 0 && $diferencial_trak != 1 && !in_array($row['enota'], [11,12])) + echo ''; + + + // Konec TR + if (($mv_count > 0 && $diferencial_trak == 1) || $diferencial_trak != 1) + echo ' ' . "\n"; + } + + // Izris naslovne vrstice tabele za checkbox tabelo + private function displayMulticheckboxHeader($spremenljivka, $row, $srv_grids, $mv_count, $cssAlign, $middle_row=false, $hideLabels){ + global $lang; + + // Preverimo, ce ponavljamo glavo - potem ji dodamo class in jo z JS ponovimo + $spremenljivkaParams = new enkaParameters($row['params']); + $grid_repeat_header = ($spremenljivkaParams->get('grid_repeat_header') ? $spremenljivkaParams->get('grid_repeat_header') : 0); + + // Zacetek TR + echo ' 0 ? 'repeat_header' : '').'">' . "\n"; + if ($hideLabels == false) { + echo ' ' . "\n"; + echo ' ' . "\n"; + } + + + if (count($srv_grids) > 0) { + + $first_missing_value = true; + + foreach ($srv_grids AS $g_id => $srv_grid) { + + # dodamo spejs pred manjkajočimi vrednostmi + if ((string)$srv_grid['other'] != '0' && $first_missing_value == true) { + echo ''; + $first_missing_value = false; + } + + // Datapiping + $srv_grid['naslov'] = Helper::dataPiping($srv_grid['naslov']); + + # izpišemo labelo grida + echo '' . $srv_grid['naslov'] . '' . "\n"; + } + } + + + // Konec TR + echo ' ' . "\n"; + } +} \ No newline at end of file -- cgit v1.2.3