0) {
self::$anketa = (int)$anketa;
}
elseif (isset ($_GET['anketa']) && (int)$_GET['anketa'] > 0) {
self::$anketa = $_GET['anketa'];
}
elseif (isset ($_POST['anketa']) && (int)$_POST['anketa'] > 0) {
self::$anketa = $_POST['anketa'];
}
# polovimo nastavitve ankete če obstaja
if (self::$anketa != null && (int)self::$anketa > 0) {
SurveyInfo::getInstance()->SurveyInit(self::$anketa);
SurveyInfo::getInstance()->resetSurveyData();
self::$missing_values_type = SurveyInfo::getInstance()->getSurveyColumn('missing_values_type') == 1 ? 1 : 0;
# če še nismo nastavili manjkajočih vrednosti jih prepišemo iz sistemskih
if ((int)self::$missing_values_type == 0) {
self :: SetUpSurvyeMissingValues();
}
}
self::Init();
}
}
/** Inicializacija, prebere sistemske vrednoasti iz baze
*
*/
static function Init() {
# če nimamo missingov dodamo sistemske
$countSystem = "SELECT count(*) FROM srv_missing_values WHERE sid='".self::$anketa."'" ;
list($cntMissing) = mysqli_fetch_row(sisplet_query($countSystem));
if ((int)$cntMissing == 0) {
self::useSystemMissingValues();
}
# preberemo sistemske nastavitve
self::selectSysNeodgovori();
self::selectSysNeopredeljeni();
self::selectSysUserSet();
}
# AJAX funkcije
/** Ajax handler
*
*/
public function ajax() {
if ($_GET['a'] == 'sysMissingValuesChangeMode') {
$_mode = $_POST['mode'];
if ($_mode == 'normal') {
self::displayNormalMode($_mode);
}
if ($_mode == 'edit') {
self::sysMissingValuesChangeMode($_mode);
}
if ($_mode == 'new') {
self::sysMissingValuesChangeMode($_mode);
}
}
if ($_GET['a'] == 'sysMissingValuesSave') {
self::SaveSystemFilters( $_POST['id'], $_POST['filter'], $_POST['text']);
self::Init();
$_mode = 'edit';
self::sysMissingValuesChangeMode($_mode);
}
if ($_GET['a'] == 'sysMissingValuesAdd') {
self::AddSystemFilters( $_POST['filter'], $_POST['text'], $_POST['filter']);
self::Init();
$_mode = 'edit';
self::sysMissingValuesChangeMode($_mode);
}
if ($_GET['a'] == 'sysMissingValuesDelete') {
self::DeleteSystemFilters($_POST['id']);
self::Init();
$_mode = 'edit';
self::sysMissingValuesChangeMode($_mode);
}
if ($_GET['a'] == 'changeSurveyMissingSettings') {
self::saveMisingValueTypeForSurvey();
self::displayMissingForSurvey();
}
if ($_GET['a'] == 'useSystemMissingValues') {
self::useSystemMissingValues();
self::displayMissingForSurvey();
}
if ($_GET['a'] == 'saveSurveyMissingValue') {
self::saveSurveyMissingValue();
self::displayMissingForSurvey();
}
if ($_GET['a'] == 'srv_missing_confirm_delete') {
self::deleteMissingForSurvey();
self::displayMissingForSurvey();
}
if ($_GET['a'] == 'srv_missing_add_new') {
self::displayAddMissingValue();
}
if ($_GET['a'] == 'srv_missing_confirm_add') {
self::addSurveyFilters();
}
if ($_GET['a'] == 'srv_missing_display') {
self::displayMissingForSurvey();
}
}
/* polovi sistemske neodgovore,
* type = 1
*/
private static function selectSysNeodgovori() {
self::$sysNeodgovori = array();
$str_select = "SELECT filter,text FROM srv_sys_filters WHERE type = 1";
$qry_select = sisplet_query($str_select);
while ($row_select = mysqli_fetch_assoc($qry_select)) {
self::$sysNeodgovori[$row_select['filter']] = $row_select['text'];
}
}
/* polovi sistemske neopredeljene,
* type = 2
*/
private static function selectSysNeopredeljeni() {
self::$sysNeopredeljeni = array();
$str_select = "SELECT filter,text FROM srv_sys_filters WHERE type = 2";
$qry_select = sisplet_query($str_select);
while ($row_select = mysqli_fetch_assoc($qry_select)) {
self::$sysNeopredeljeni[$row_select['filter']] = $row_select['text'];
}
}
/* polovi sistemske uporabniško nastavljene,
* type = 3
*/
private static function selectSysUserSet() {
self::$sysUserSet = array();
$str_select = "SELECT filter,text FROM srv_sys_filters WHERE type = 3";
$qry_select = sisplet_query($str_select);
while ($row_select = mysqli_fetch_assoc($qry_select)) {
self::$sysUserSet[$row_select['filter']] = $row_select['text'];
}
}
/** polovimo missinge za anketo
* če obstaja nastavitev za anketo, (TODO)
* če ne vzamemo privzete sistenmske misinge
*
*
* @var unknown_type
*/
private static $_systemFiltersByType = array();
static function GetSystemFlterByType($type, $forceSystem = false) {
global $lang;
if (is_array($type)) {
$type = (string)implode(',',$type);
$_type = "type IN (".$type.")";
} else {
$_type = "type = '".$type."'";
}
if (isset(self::$_systemFiltersByType[$type])) {
return self::$_systemFiltersByType[$type];
} else {
$result = array();
# preverimo iz katere tabele lovimo lahko imamo na nivoju ankete ali na nivoju sistema
if ((int)self::$missing_values_type == 1 && $forceSystem == false) {
$stringSystemSetting_filters = "SELECT value AS filter, text FROM srv_missing_values WHERE sid='".self::$anketa."' AND ".$_type." AND active = 1 ORDER BY type ASC, value ASC" ;
} else {
$stringSystemSetting_filters = "SELECT filter, text FROM srv_sys_filters WHERE ".$_type." ORDER BY filter ASC";
}
$sqlSystemSetting_filters = sisplet_query($stringSystemSetting_filters );
while ( $rowSystemSetting_filters = mysqli_fetch_assoc($sqlSystemSetting_filters) )
{
# naredimo prevode:
$result[$rowSystemSetting_filters['filter']] = isset($lang['srv_mv_'.$rowSystemSetting_filters['text']]) ? $lang['srv_mv_'.$rowSystemSetting_filters['text']] : $rowSystemSetting_filters['text'];;
}
self::$_systemFiltersByType[$type] = $result;
return self::$_systemFiltersByType[$type];
}
}
# urejanje sistemskih missingov
/* Prikaže osnovni okvir za urejanje missingov
*
*/
static public function SystemFilters() {
global $lang;
echo '
';
}
/** Prikaže navaden način misingov - predogled
*
* @param $_mode
*/
private static function displayNormalMode($_mode = null) {
global $lang;
//echo '';
echo '';
echo ''
.$lang['srv_settings_filter_edit_mode']. '';
echo '';
echo '';
echo '
';
echo ''.$lang['srv_filter_vrednost'].'';
echo '
';
echo '
';
echo ''.$lang['srv_filter_variabla'].'';
echo '
';
echo '
';
# neodgovori
if ( count(self::$sysNeodgovori) > 0 ) {
foreach ( self::$sysNeodgovori as $key => $text) {
echo '';
echo '
'.$key.'
';
echo '
'.$text.'
';
echo '
';
}
}
# neopredeljeni
if ( count(self::$sysNeopredeljeni) > 0 ) {
foreach ( self::$sysNeopredeljeni as $key => $text) {
echo '';
echo '
'.$key.'
';
echo '
'.$text.'
';
echo '
';
}
}
# uporabniški
if ( count(self::$sysUserSet) > 0 ) {
foreach ( self::$sysUserSet as $key => $text) {
echo '';
echo '
'.$key.'
';
echo '
'.$text.'
';
echo '
';
}
}
}
/** Prikaže edit mode za misinge
*
* @param unknown_type $mode
*/
private static function sysMissingValuesChangeMode($mode = '') {
global $lang;
echo '';
echo ''
.$lang['srv_settings_filter_view_mode']. '';
echo '';
echo '
';
echo ''.$lang['srv_filter_vrednost'].'';
echo '
';
echo '
';
echo ''.$lang['srv_filter_variabla'].'';
echo '
';
echo '
';
# neodgovori
if ( count(self::$sysNeodgovori) > 0 ) {
foreach ( self::$sysNeodgovori as $key => $text) {
echo '';
}
}
# neopredeljeni
if ( count(self::$sysNeopredeljeni) > 0 ) {
foreach ( self::$sysNeopredeljeni as $key => $text) {
echo '';
}
}
# User defined
if ( count(self::$sysUserSet) > 0 ) {
foreach ( self::$sysUserSet as $key => $text) {
echo '';
echo '
';
echo ' ';
echo '
';
echo '
';
echo ' ';
echo '
';
echo '
';
echo '
';
}
}
echo '';
if ($mode == 'new')
{
echo '
';
echo '
';
echo '';
echo '
';
echo '
';
echo '';
echo '
';
echo '
';
echo '
';
echo '
';
} else {
echo '
'.$lang['srv_novfilter'].'';
}
echo '
';
// pohendlamo error: duplicate
if (self::$mySqlErrNo == 1062)
{
echo '
';
echo $lang['srv_duplicateEntry'];
echo '
';
}
}
/** Doda sistemski missing
*
* @param $filter
* @param $text
* @param $fid
*/
static function AddSystemFilters( $filter, $text, $fid) {
global $global_user_id;
self::$mySqlErrNo = null;
$insertString = "INSERT INTO srv_sys_filters (fid,filter,text,uid,type) ".
"VALUES ('".$fid."', '".$filter."', '".$text."', '".$global_user_id."', '3');";
$mySqlResult = sisplet_query($insertString);
self::$mySqlErrNo = mysqli_errno($GLOBALS['connect_db']);
}
/** Izbriše sistemski missing
*
* @param $id
*/
static function DeleteSystemFilters( $id) {
self::$mySqlErrNo = null;
$deleteString = "DELETE FROM srv_sys_filters WHERE filter = '".$id."' AND type = '3'";
$mySqlResult = sisplet_query($deleteString);
self::$mySqlErrNo = mysqli_errno($GLOBALS['connect_db']);
}
/** Shrani sistemski missing
*
* @param $id
* @param $filter
* @param $text
*/
static function SaveSystemFilters($id,$filter,$text) {
self::$mySqlErrNo = null;
$updateString = "UPDATE srv_sys_filters " .
"SET filter = '".$filter."', text = '".$text."' ".
"WHERE filter = '".$id."'";
$mySqlResult = sisplet_query($updateString);
self::$mySqlErrNo = mysqli_errno($GLOBALS['connect_db']);
}
/** Vrne manjkajoče vrednosti za anketo
* # če ni nastavljeno na nivoju ankete vrne sistemske nastavitve
*
*/
static public function GetUnsetValuesForSurvey($type = array(2,3)) {
# TODO preverit ali je na nivoju ankete če ne na nivoju sistema
return self::GetSystemFlterByType($type);
}
/** Vrne neodgovore za anketo
* # če ni nastavljeno na nivoju ankete vrne sistemske nastavitve
*
*/
static public function GetMissingValuesForSurvey($type = array(1)) {
# TODO preverit ali je na nivoju ankete če ne na nivoju sistema
return self::GetSystemFlterByType($type);
}
static public function GetSurveyMissingValues($anketa_id = null) {
if ($anketa_id == null) {
$anketa_id = self::$anketa;
}
$result = array();
if ($anketa_id != null && $anketa_id > 0) {
$stringSurveyMissingValues = "SELECT * FROM srv_missing_values WHERE sid ='".$anketa_id ."' AND active = '1' ORDER BY type ASC, systemValue DESC,value ASC";
$sqlSurveyMissingValues = sisplet_query($stringSurveyMissingValues);
while ( $row = mysqli_fetch_assoc($sqlSurveyMissingValues) ) {
$result[$row['type']][] = array('value'=>$row['value'],'text'=> $row['text'],'defSysVal'=>$row['systemValue']);
}
}
return $result;
}
static public function displayMissingForSurvey() {
global $lang;
self::displayLeftNavigation('start');
$si_mv = SurveyInfo::getInstance()->getSurveyColumn('missing_values_type') == 1 ? '1' : '0';
echo '
';
echo '';
echo '
';
echo '';
self::displayLeftNavigation();
}
/* shranimo tip missingov za anketo
*
*/
static private function saveMisingValueTypeForSurvey() {
if (self::$anketa) {
$missing_values_type = (isset($_POST['missing_values_type']) && $_POST['missing_values_type'] == '1') ? '1' : '0';
$updateString = "UPDATE srv_anketa SET missing_values_type = '".$missing_values_type."' WHERE id = '".self::$anketa."'";
$mySqlResult = sisplet_query($updateString);
}
#uprejtamo timestamp
Common::updateEditStamp();
SurveyInfo::getInstance()->resetSurveyData();
}
/* Na nivoju ankete nastavimo enake majkajoče vrednosti kot so sistemske
*
*/
static private function useSystemMissingValues() {
if (self::$anketa) {
# najprej pobrišemo vse missinge ki so nastavljeni za obstoječo anketo
$deleteString = "DELETE FROM srv_missing_values WHERE sid = '".self::$anketa."'";
sisplet_query($deleteString);
# nato prekopiramo sistemske missinge v anketo
$sf_1 = self::GetSystemFlterByType(array(1),true);
$sf_2 = self::GetSystemFlterByType(array(2),true);
$sf_3 = self::GetSystemFlterByType(array(3),true);
if ( ( count($sf_1) + count($sf_2)+ count($sf_3) ) > 0) {
$insertString = "INSERT INTO srv_missing_values (sid,type,value,text,active,systemValue) VALUES ";
$prefix = '';
foreach ($sf_1 AS $key => $value) {
$insertString.= $prefix."( '".self::$anketa."', '1', '$key', '".addslashes($value)."', '1','$key')";
$prefix = ', ';
}
foreach ($sf_2 AS $key => $value) {
$insertString.= $prefix."( '".self::$anketa."', '2', '$key', '".addslashes($value)."', '1','$key')";
$prefix = ', ';
}
foreach ($sf_3 AS $key => $value) {
$insertString.= $prefix."( '".self::$anketa."', '3', '$key', '".addslashes($value)."', '1','$key')";
$prefix = ', ';
}
$mySqlResult = sisplet_query($insertString);
self::$mySqlErrNo = mysqli_errno($GLOBALS['connect_db']);
}
#uprejtamo timestamp
Common::updateEditStamp();
}
}
private static function saveSurveyMissingValue() {
list($_mv, $_what, $_type, $_old_value) = explode('_',$_POST['el_id']);
$new_value = str_replace('_','',$_POST['new_value']);
if ( isset($_type) && $_type != '' &&
( $_what == 'text' || $_what == 'value' ) &&
isset($_old_value) && $_old_value != '' && is_numeric($_old_value) &&
isset($new_value) && $new_value != '' && is_numeric($new_value) &&
isset(self::$anketa) && self::$anketa > 0) {
$updateString = "UPDATE srv_missing_values " .
"SET $_what = '".$new_value."' ".
"WHERE sid = '".self::$anketa."' AND type='".$_type."' AND value = '".$_old_value."'";
$mySqlResult = sisplet_query($updateString);
self::$mySqlErrNo = mysqli_errno($GLOBALS['connect_db']);
# updejtamo še srv_vrednost, če smo slučajno imeli že nastavljen missing
$selStr = "SELECT v.id FROM srv_vrednost v, srv_spremenljivka s, srv_grupa g WHERE v.spr_id=s.id AND s.gru_id=g.id AND g.ank_id='".self::$anketa."' AND v.other='$_old_value'";
list($vre_id) = mysqli_fetch_row(sisplet_query($selStr));
if ((int)$vre_id > 0) {
$updateVreString = "UPDATE srv_vrednost SET variable = '$new_value', other='$new_value' WHERE id ='$vre_id'";
$sqlVreResult = sisplet_query($updateVreString);
self::$mySqlErrNo = mysqli_errno($GLOBALS['connect_db']);
}
#uprejtamo timestamp
Common::updateEditStamp();
}
}
private static function deleteMissingForSurvey() {
list($_mv, $_what, $_type, $_value) = explode('_',$_POST['delete_id']);
if ( isset($_type) && $_type != '' &&
$_what == 'img' &&
isset($_value) && $_value != '' &&
isset(self::$anketa) && self::$anketa > 0) {
$deleteString = "DELETE FROM srv_missing_values " .
"WHERE sid = '".self::$anketa."' AND type='".$_type."' AND value = '".$_value."'";
$mySqlResult = sisplet_query($deleteString);
#uprejtamo timestamp
Common::updateEditStamp();
}
}
private static function SetUpSurvyeMissingValues() {
self::useSystemMissingValues();
$updateString = "UPDATE srv_anketa SET missing_values_type = '1' WHERE id = '".self::$anketa."'";
$mySqlResult = sisplet_query($updateString);
SurveyInfo::getInstance()->resetSurveyData();
#uprejtamo timestamp
Common::updateEditStamp();
}
private function displayAddMissingValue() {
global $lang;
echo '';
}
private function addSurveyFilters() {
if (isset($_POST['mv_add_filter']) && trim($_POST['mv_add_filter']) != ""
&& isset($_POST['mv_add_text']) && trim($_POST['mv_add_text']) != "") {
$insertString = "INSERT INTO srv_missing_values (sid,type,value,text,active) VALUES ( '".self::$anketa."', '3', '".$_POST['mv_add_filter']."', '".addslashes($_POST['mv_add_text'])."', '1') ON DUPLICATE KEY UPDATE value='".$_POST['mv_add_filter']."', text='".addslashes($_POST['mv_add_text'])."', active='1'";
$mySqlResult = sisplet_query($insertString);
if (!$mySqlResult) {
echo 'Napaka! ';
return;
} else {
#updejtamo timestamp
Common::updateEditStamp();
echo 'true';
return;
}
} else {
echo 'Napaka! Polja ne smejo biti prazna';
return;
}
}
private static function displayLeftNavigation($what=null) {
if ($_REQUEST['a'] != 'missing') {
if ($what == 'start') {
$sa=new SurveyAdmin(self::$anketa);
echo '';
$sa->showGlobalSettingsLinks();
$sa->showAdditionalSettingsLinks();
echo '
';
}
}
}
}
?>