0) { $this->anketa = $anketa; } else { die("Napaka!"); } } public function quota_display($condition, $long_alert=0) { global $lang; $echo = ''; $echo .= ''; if ($condition < 0) { $rowC = Cache::srv_spremenljivka($condition < 0 ? -$condition : $condition); $echo .= $rowC['variable'].' = '; } $sql = sisplet_query("SELECT * FROM srv_quota WHERE cnd_id = '$condition' ORDER BY vrstni_red ASC"); if (!$sql) echo mysqli_error($GLOBALS['connect_db']); $bracket = 0; $i = 0; while ($row = mysqli_fetch_array($sql)) { if ($i++ != 0) if ($row['operator'] == 0) $echo .= ' + '; elseif ($row['operator'] == 1) $echo .= ' - '; elseif ($row['operator'] == 2) $echo .= ' * '; elseif ($row['operator'] == 3) $echo .= ' / '; for ($i=1; $i<=$row['left_bracket']; $i++) if ($long_alert == 1) $echo .= ' ( '; else $echo .= ' ( '; // Pri kvotah imamo vedno count $echo .= $lang['srv_quota'].' ('; // spremenljivke if ($row['spr_id'] > 0) { // obicne spremenljivke if ($row['vre_id'] == 0) { $row1 = Cache::srv_spremenljivka($row['spr_id']); if ($row1['tip'] != 7) { $variable = $row1['variable']; } // number else { $variable = $row1['variable'].'['.($row['grd_id']+1).']'; } } // multigrid, checkbox, radio elseif ($row['grd_id'] == 0) { $sql1 = sisplet_query("SELECT variable FROM srv_vrednost WHERE id = '$row[vre_id]'"); if (!$sql1) echo mysqli_error($GLOBALS['connect_db']); $row1 = mysqli_fetch_array($sql1); $rowS = Cache::srv_spremenljivka($row['spr_id']); if ($rowS['tip'] != 1) { $variable = $row1['variable']; } else{ $variable = $rowS['variable'].'_'.$row1['variable']; } } // multichecckbox, multinumber elseif ($row['grd_id'] > 0) { $sql1 = sisplet_query("SELECT variable FROM srv_vrednost WHERE id = '$row[vre_id]'"); if (!$sql1) echo mysqli_error($GLOBALS['connect_db']); $row1 = mysqli_fetch_array($sql1); $sql1g = sisplet_query("SELECT variable FROM srv_grid WHERE id = '$row[grd_id]'"); if (!$sql1g) echo mysqli_error($GLOBALS['connect_db']); $row1g = mysqli_fetch_array($sql1g); $variable = $row1['variable'].'['.$row1g['variable'].']'; } if ($long_alert) $echo .= ''; $echo .= $variable; if ($long_alert) $echo .= ''; // konstante } elseif ($row['spr_id'] < 0) { $echo .= $lang['srv_quota_status_'.(-1*$row['spr_id'])]; } // Pri kvotah imamo vedno count $echo .= ')'; for ($i=1; $i<=$row['right_bracket']; $i++) if ($long_alert == 1) $echo .= ' ) '; else $echo .= ' ) '; } $echo .= ''; if ($long_alert) { $quota_check = $this->quota_check($condition); if ( $quota_check != 0) { if ($quota_check == 1) $echo .= '
'.$lang['srv_error_spremenljivka'].''; elseif ($quota_check == 2) $echo .= '
'.$lang['srv_error_spremenljivka'].''; elseif ($quota_check == 3) $echo .= '
'.$lang['srv_error_oklepaji'].''; } } return $echo; } // Izpise urejanje kvote private function quota_editing ($condition, $vrednost=0) { global $lang; echo ''; echo '
'; $this->quota_editing_inner($condition, $vrednost); echo '
'; echo '
'; $row = Cache::srv_spremenljivka(-$condition); if ($condition < 0) { echo '
'; echo '
'; echo ' '; echo ' '; echo '
'; echo '
'; } echo '
'; echo '
'; echo '
'; // kalkulacija kot spremenljivka (lahko jo zbrisemo) if ($condition < 0) echo ' '; echo ' '; echo ' '; echo '
'; echo '
'; ?>'; echo '

'.$lang['srv_quota'].'

'; echo '
'; echo $this->quota_display($condition, 1); echo '
'; echo ''; echo '
'; $sql = sisplet_query("SELECT id FROM srv_quota WHERE cnd_id = '$condition' ORDER BY vrstni_red"); if (mysqli_num_rows($sql) == 0) { sisplet_query("INSERT INTO srv_quota (id, cnd_id, vrstni_red) VALUES ('', '$condition', '1')"); $sql = sisplet_query("SELECT id FROM srv_quota WHERE cnd_id = '$condition' ORDER BY vrstni_red"); } while ($row = mysqli_fetch_array($sql)) { $this->quota_edit($row['id'], $vrednost); } echo '

'.$lang['srv_add_cond'].':  + ,  - ,  * ,  / 

'; echo '
'; } /** * @desc vrstica v urejanju kvot */ private function quota_edit ($quota, $vrednost=0) { global $lang; $b = new Branching($this->anketa); $sql = sisplet_query("SELECT * FROM srv_quota WHERE id = '$quota'"); if (!$sql) echo mysqli_error($GLOBALS['connect_db']); $row = mysqli_fetch_array($sql); $sql1 = sisplet_query("SELECT if_id FROM srv_condition WHERE id = '{$row['cnd_id']}'"); $row1 = mysqli_fetch_array($sql1); if ($row['cnd_id'] > 0) { // kalkulacija znotraj pogoja $vrstni_red = $b->vrstni_red($b->find_before_if($row1['if_id'])); } else { // kalkulacija kot spremenljivka $vrstni_red = $b->vrstni_red(-$row['cnd_id']) - 1; // -1 je da ne prikaze se trenutne kalkulacije } $sql_count = sisplet_query("SELECT COUNT(*) AS count FROM srv_quota WHERE cnd_id='$row[cnd_id]'"); if (!$sql_count) die(); $row_count = mysqli_fetch_array($sql_count); // operator if ($row['vrstni_red'] > 1) { echo '
'; if ($row['operator']==0) echo ' + '; if ($row['operator']==1) echo ' - '; if ($row['operator']==2) echo ' * '; if ($row['operator']==3) echo ' / '; echo '
'; } // form echo '
'."\n\r"; echo '
'; // move echo '
'; if ($row_count['count'] != 1 ) echo ''; echo '
'; // Srednji bel del echo '
'; // left_bracket echo '
'; if ($row_count['count'] != 1 || $row['left_bracket']>0 || $row['right_bracket']>0) { echo '
'; echo ''; if ($row['left_bracket'] > 0) echo ''; else echo ''; echo '
'; echo '
'.$lang['srv_oklepaji'].'
'; } echo '
'; // left_bracket echo '
'; for ($i=$row['left_bracket']; $i>0; $i--) { echo ' ( '; } echo '
'; // spremenljivka echo '
'; if ($row['spr_id']==0) echo ''.$lang['srv_select_spr'].'!'; echo ''; echo '
'; // right_bracket echo '
'; for ($i=$row['right_bracket']; $i>0; $i--) { echo ' ) '; } echo '
'; // right_bracket buttons echo '
'; if ($row_count['count'] != 1 || $row['right_bracket']>0 || $row['left_bracket']>0) { echo '
'; if ($row['right_bracket'] > 0) echo ''; else echo ''; echo ''; echo '
'; echo '
'.$lang['srv_zaklepaji'].'
'; } echo '
'; echo '
'; // remove echo '
'; $sql3 = sisplet_query("SELECT id FROM srv_quota WHERE cnd_id='$row[cnd_id]'"); if (mysqli_num_rows($sql3) != 1 ) echo ' '."\n\r"; echo '
'; echo '
'; echo '
'."\n\r"; } /** * @desc preveri ali so oklepaji pravilno postavljeni v kalkulacijah (presteje predoklepaje in zaklepaje) * in pa ce je izbrana spremenljivka */ private function quota_check ($condition) { $sql = sisplet_query("SELECT spr_id, left_bracket, right_bracket FROM srv_quota WHERE cnd_id='$condition' ORDER BY vrstni_red"); if (!$sql) echo mysqli_error($GLOBALS['connect_db']); if (mysqli_num_rows($sql) == 0) return 1; // ni sploh se izbrana spremenljivka (ker ni quota sploh se inicializiran z default vrstico) $bracket = 0; while ($row = mysqli_fetch_array($sql)) { if ($row['spr_id'] == 0) // ce ni izbrana spremenljivka v eni od vrstic return 2; $bracket = $bracket + $row['left_bracket'] - $row['right_bracket']; if ($bracket < 0) return 3; // oklepaj } if ($bracket == 0) return 0; // vse ok else return 3; // zaklepaj } public function ajax() { global $global_user_id; global $lang; global $site_path; if (isset($_POST['anketa'])) $this->anketa = $_POST['anketa']; if (isset($_POST['spremenljivka'])) $this->spremenljivka = $_POST['spremenljivka']; $ajax = 'ajax_' . $_GET['a']; if ( method_exists('SurveyQuotas', $ajax) ) $this->$ajax(); else echo 'method '.$ajax.' does not exist'; } private function ajax_quota_editing () { if ($_POST['noupdate'] != 1) { Common::updateEditStamp(); } $condition = $_POST['condition']; $vrednost = $_POST['vrednost']; $sql = sisplet_query("SELECT vre_id FROM srv_condition WHERE id = '$condition'"); $row = mysqli_fetch_array($sql); $quota = $this->quota_editing($condition, $vrednost); if ($row['vre_id'] == 0) { $s = sisplet_query("UPDATE srv_condition SET vre_id='$quota' WHERE id='$condition'"); if (!$s) echo mysqli_error($GLOBALS['connect_db']); } } private function ajax_quota_editing_close () { $condition = $_POST['condition']; $vrednost = $_POST['vrednost']; $sql = sisplet_query("SELECT if_id FROM srv_condition WHERE id = '$condition'"); $row = mysqli_fetch_array($sql); $b = new Branching($this->anketa); if ($condition >= 0) $b->condition_editing($row['if_id'], $vrednost); else { $row = SurveyInfo::getInstance()->getSurveyRow(); if ($row['expanded'] == 1) { $b->vprasanje(-$condition); } else { $b->spremenljivka_name(-$condition); } } } private function ajax_quota_save () { if ($_POST['noupdate'] != 1) { Common::updateEditStamp(); } $quota = $_POST['quota']; $expression = $_POST['expression']; sisplet_query("UPDATE srv_quota SET expression='$expression' WHERE id = '$quota'"); } private function ajax_quota_add () { if ($_POST['noupdate'] != 1) { Common::getInstance()->Init($this->anketa); Common::getInstance()->updateEditStamp(); } $condition = $_POST['condition']; $operator = $_POST['operator']; $vrednost = $_POST['vrednost']; $sql = sisplet_query("SELECT MAX(vrstni_red) AS max FROM srv_quota WHERE cnd_id = '$condition'"); $row = mysqli_fetch_array($sql); $vrstni_red = $row['max'] + 1; $s = sisplet_query("INSERT INTO srv_quota (id, cnd_id, operator, vrstni_red) VALUES ('', '$condition', '$operator', '$vrstni_red')"); if (!$s) echo mysqli_error($GLOBALS['connect_db']); $this->quota_editing_inner($condition, $vrednost); } private function ajax_quota_operator_edit () { if ($_POST['noupdate'] != 1) { Common::getInstance()->Init($this->anketa); Common::getInstance()->updateEditStamp(); } $quota = $_POST['quota']; $operator = $_POST['operator']; sisplet_query("UPDATE srv_quota SET operator='$operator' WHERE id = '$quota'"); $sql = sisplet_query("SELECT cnd_id FROM srv_quota WHERE id = '$quota'"); if (!$sql) echo mysqli_error($GLOBALS['connect_db']); $row = mysqli_fetch_array($sql); $this->quota_editing_inner($row['cnd_id'], $_POST['vrednost']); } private function ajax_quota_edit () { if ($_POST['noupdate'] != 1) { Common::getInstance()->Init($this->anketa); Common::getInstance()->updateEditStamp(); } $spremenljivka = $_POST['spremenljivka']; $quota = $_POST['quota']; $value = $_POST['value']; $vrednost = $_POST['vrednost']; $grd_id = 0; // obicna spremenljivka if (is_numeric($spremenljivka)) { $spr_id = $spremenljivka; $vre_id = 0; // checkbox, multigrid } elseif ( strpos($spremenljivka, 'vre_') !== false ) { $e = explode('_', $spremenljivka); list( , $vre_id, $grd_id) = $e; $sql2 = sisplet_query("SELECT spr_id FROM srv_vrednost WHERE id = '$vre_id'"); $row2 = mysqli_fetch_array($sql2); $spr_id = $row2['spr_id']; // number } elseif ( strpos($spremenljivka, 'num_') !== false ) { $e = explode('_', $spremenljivka); list( , $spr_id, $grd_id) = $e; $vre_id = 0; // multicheckbox, multinumber } else { $e = explode('_', $spremenljivka); list( , $spr_id, $vre_id, $grd_id) = $e; } if (!is_numeric($value)) $value = 0; $s = sisplet_query("UPDATE srv_quota SET spr_id='$spr_id', vre_id='$vre_id', grd_id='$grd_id', value='$value' WHERE id = '$quota'"); if (!$s) echo mysqli_error($GLOBALS['connect_db']); $sql = sisplet_query("SELECT cnd_id FROM srv_quota WHERE id = '$quota'"); if (!$sql) echo mysqli_error($GLOBALS['connect_db']); $row = mysqli_fetch_array($sql); $this->quota_editing_inner($row['cnd_id'], $vrednost); } private function ajax_quota_value_edit (){ if ($_POST['noupdate'] != 1) { Common::getInstance()->Init($this->anketa); Common::getInstance()->updateEditStamp(); } if(isset($_POST['spremenljivka']) && $_POST['spremenljivka'] > 0){ $spremenljivka = $_POST['spremenljivka']; $value = $_POST['value']; $s = sisplet_query("UPDATE srv_spremenljivka SET vsota_limit='$value' WHERE id = '$spremenljivka'"); if (!$s) echo mysqli_error($GLOBALS['connect_db']); } } private function ajax_quota_remove () { if ($_POST['noupdate'] != 1) { Common::getInstance()->Init($this->anketa); Common::getInstance()->updateEditStamp(); } $quota = $_POST['quota']; $vrednost = $_POST['vrednost']; sisplet_query("DELETE FROM srv_quota WHERE id='$quota'"); $b = new Branching($this->anketa); $b->repare_calculation($_POST['condition']); $this->quota_editing_inner($_POST['condition'], $vrednost); } private function ajax_quota_bracket_edit_new () { if ($_POST['noupdate'] != 1) { Common::getInstance()->Init($this->anketa); Common::getInstance()->updateEditStamp(); } $who = $_POST['who']; $what = $_POST['what']; $left_bracket = $_POST['left_bracket']; $quota = $_POST['quota']; if ($who == 'left') if ($what == 'plus') $bracket = 'left_bracket=left_bracket+1'; else $bracket = 'left_bracket=left_bracket-1'; else if ($what == 'plus') $bracket = 'right_bracket=right_bracket+1'; else $bracket = 'right_bracket=right_bracket-1'; sisplet_query("UPDATE srv_quota SET $bracket WHERE id = '$quota'"); $sql = sisplet_query("SELECT cnd_id FROM srv_quota WHERE id = '$quota'"); if (!$sql) echo mysqli_error($GLOBALS['connect_db']); $row = mysqli_fetch_array($sql); $this->quota_editing_inner($row['cnd_id'], $_POST['vrednost']); } private function ajax_quota_sort() { Common::getInstance()->Init($this->anketa); Common::getInstance()->updateEditStamp(); $condition = $_POST['condition']; $sortable = $_POST['sortable']; $sortable = explode('&', $sortable); $i=1; foreach ($sortable AS $calc) { $quota = explode('=', $calc); $quota = $quota[1]; $s = sisplet_query("UPDATE srv_quota SET vrstni_red='{$i}' WHERE id='{$quota}'"); if (!$s) echo mysqli_error($GLOBALS['connect_db']); $i++; } $b = new Branching($this->anketa); $b->repare_condition($if); $this->quota_editing_inner($condition); } private function ajax_quota_edit_variable () { Common::updateEditStamp(); if(isset($_POST['spremenljivka']) && $_POST['spremenljivka'] > 0){ $spremenljivka = $_POST['spremenljivka']; $variable = $_POST['variable']; // preverimo, da ni se kje drugje v anekti tako ime spremenljivke $sqlv = sisplet_query("SELECT s.variable FROM srv_spremenljivka s, srv_grupa g WHERE s.gru_id=g.id AND g.ank_id='$this->anketa'"); $ok = true; while ($rowv = mysqli_fetch_array($sqlv)) { if ($rowv['variable'] == $variable) $ok = false; } // Ce se ime ze pojavi v anketi mu dodamo stevilko if(!$ok){ $ok = false; $i = 2; while(!$ok){ $ok = true; $variable = $_POST['variable'].'_'.$i; $sqlv = sisplet_query("SELECT s.variable, s.id as id FROM srv_spremenljivka s, srv_grupa g WHERE s.gru_id=g.id AND g.ank_id='$this->anketa'"); while ($rowv = mysqli_fetch_array($sqlv)) { if ($rowv['variable'] == $variable && $spremenljivka != $rowv['id']){ $ok = false; $i++; } } } } sisplet_query("UPDATE srv_spremenljivka SET variable='$variable', variable_custom='1' WHERE id = '$spremenljivka'"); } } } ?>