summaryrefslogtreecommitdiffstats
path: root/admin/survey/classes/class.SurveyCopy.php
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--admin/survey/classes/class.SurveyCopy.php411
1 files changed, 305 insertions, 106 deletions
diff --git a/admin/survey/classes/class.SurveyCopy.php b/admin/survey/classes/class.SurveyCopy.php
index 08f685a..ed0da77 100644
--- a/admin/survey/classes/class.SurveyCopy.php
+++ b/admin/survey/classes/class.SurveyCopy.php
@@ -130,13 +130,15 @@ class SurveyCopy {
// preberemo array
$array = self::getArraySource( $data );
-
- $array['srv_anketa'][0]['naslov'] = $array['srv_anketa'][0]['naslov'].' '.date("j.n.Y");
-
- // zapisemo file na disk
- $fp = fopen( dirname(__FILE__) . '/../SurveyBackup/'.$array['srv_anketa'][0]['id'].'-'.date("d.m.Y-H.i.s").'.1ka', 'w');
- fwrite($fp, serialize($array));
- fclose($fp);
+
+ if(isset($array['srv_anketa'][0])){
+ $array['srv_anketa'][0]['naslov'] = $array['srv_anketa'][0]['naslov'].' '.date("j.n.Y");
+
+ // zapisemo file na disk
+ $fp = fopen( dirname(__FILE__) . '/../SurveyBackup/'.$array['srv_anketa'][0]['id'].'-'.date("d.m.Y-H.i.s").'.1ka', 'w');
+ fwrite($fp, serialize($array));
+ fclose($fp);
+ }
}
@@ -203,6 +205,21 @@ class SurveyCopy {
}
+ /**
+ * vrne array ankete
+ *
+ */
+ static function getArrayVar ( $data = false ) {
+
+ // preberemo array
+ $array = self::getArraySource( $data );
+
+ $array['srv_anketa'][0]['naslov'] = $array['srv_anketa'][0]['naslov'].' '.date("j.n.Y");
+
+ // izpisemo serializiran array
+ return $array;
+ }
+
static function setSourceArray ($array) {
self::$source_array = $array;
}
@@ -215,13 +232,6 @@ class SurveyCopy {
$arr_src = array();
- // subqueryji mysql cist ubijejo zato sem razbil v 2 locena queryja... v bistvu si zakesiramo seznam spremenljivk in ifov
- // TODO ko se MySQL upgrada na 5.6 mogoce prestavit nazaj na navaden subquery, ali pa tut ne - bo za sprobat
-
-
- $qry_src_survey = sisplet_query("SELECT * FROM srv_anketa WHERE id = '".self :: $src_survey."'", self :: $src_connect_db);
- $anketa_array = self::sql2array($qry_src_survey);
-
//Če imamo vklopljeno hierarhijo, potem vrednosti spremenljivk od hierarhije ne kopiramo
// V kolikor imamo vklopljeno hierarhijo potem ne kopiramo spremenljivke od hierarhije
$hierarhija_sql = null;
@@ -380,8 +390,14 @@ class SurveyCopy {
$qry_src_user = sisplet_query("SELECT * FROM srv_user WHERE ank_id = '".self::$src_survey."'", self :: $src_connect_db);
$arr_src['srv_user'] = self::sql2array($qry_src_user);
- $qry_src_data_checkgrid = sisplet_query("SELECT * FROM srv_data_checkgrid WHERE spr_id IN (".$qry_cache_spr_id.")", self :: $src_connect_db);
- $arr_src['srv_data_checkgrid'] = self::sql2array($qry_src_data_checkgrid);
+ $qry_src_data_checkgrid_archive1 = sisplet_query("SELECT * FROM srv_data_checkgrid_archive1 WHERE spr_id IN (".$qry_cache_spr_id.")", self :: $src_connect_db);
+ $arr_src['srv_data_checkgrid_archive1'] = self::sql2array($qry_src_data_checkgrid_archive1);
+
+ $qry_src_data_checkgrid_archive2 = sisplet_query("SELECT * FROM srv_data_checkgrid_archive2 WHERE spr_id IN (".$qry_cache_spr_id.")", self :: $src_connect_db);
+ $arr_src['srv_data_checkgrid_archive2'] = self::sql2array($qry_src_data_checkgrid_archive2);
+
+ $qry_src_data_checkgrid_archive3 = sisplet_query("SELECT * FROM srv_data_checkgrid_archive3 WHERE spr_id IN (".$qry_cache_spr_id.")", self :: $src_connect_db);
+ $arr_src['srv_data_checkgrid_archive3'] = self::sql2array($qry_src_data_checkgrid_archive3);
$qry_src_data_checkgrid_active = sisplet_query("SELECT * FROM srv_data_checkgrid_active WHERE spr_id IN (".$qry_cache_spr_id.")", self :: $src_connect_db);
$arr_src['srv_data_checkgrid_active'] = self::sql2array($qry_src_data_checkgrid_active);
@@ -389,8 +405,14 @@ class SurveyCopy {
$qry_src_data_glasovanje = sisplet_query("SELECT * FROM srv_data_glasovanje WHERE spr_id IN (".$qry_cache_spr_id.")", self :: $src_connect_db);
$arr_src['srv_data_glasovanje'] = self::sql2array($qry_src_data_glasovanje);
- $qry_src_data_grid = sisplet_query("SELECT * FROM srv_data_grid WHERE spr_id IN (".$qry_cache_spr_id.")", self :: $src_connect_db);
- $arr_src['srv_data_grid'] = self::sql2array($qry_src_data_grid);
+ $qry_src_data_grid_archive1 = sisplet_query("SELECT * FROM srv_data_grid_archive1 WHERE spr_id IN (".$qry_cache_spr_id.")", self :: $src_connect_db);
+ $arr_src['srv_data_grid_archive1'] = self::sql2array($qry_src_data_grid_archive1);
+
+ $qry_src_data_grid_archive2 = sisplet_query("SELECT * FROM srv_data_grid_archive2 WHERE spr_id IN (".$qry_cache_spr_id.")", self :: $src_connect_db);
+ $arr_src['srv_data_grid_archive2'] = self::sql2array($qry_src_data_grid_archive2);
+
+ $qry_src_data_grid_archive3 = sisplet_query("SELECT * FROM srv_data_grid_archive3 WHERE spr_id IN (".$qry_cache_spr_id.")", self :: $src_connect_db);
+ $arr_src['srv_data_grid_archive3'] = self::sql2array($qry_src_data_grid_archive3);
$qry_src_data_grid_active = sisplet_query("SELECT * FROM srv_data_grid_active WHERE spr_id IN (".$qry_cache_spr_id.")", self :: $src_connect_db);
$arr_src['srv_data_grid_active'] = self::sql2array($qry_src_data_grid_active);
@@ -398,14 +420,26 @@ class SurveyCopy {
$qry_src_data_rating = sisplet_query("SELECT * FROM srv_data_rating WHERE spr_id IN (".$qry_cache_spr_id.")", self :: $src_connect_db);
$arr_src['srv_data_rating'] = self::sql2array($qry_src_data_rating);
- $qry_src_data_text = sisplet_query("SELECT * FROM srv_data_text WHERE spr_id IN (".$qry_cache_spr_id.")", self :: $src_connect_db);
- $arr_src['srv_data_text'] = self::sql2array($qry_src_data_text);
+ $qry_src_data_text_archive1 = sisplet_query("SELECT * FROM srv_data_text_archive1 WHERE spr_id IN (".$qry_cache_spr_id.")", self :: $src_connect_db);
+ $arr_src['srv_data_text_archive1'] = self::sql2array($qry_src_data_text_archive1);
+
+ $qry_src_data_text_archive2 = sisplet_query("SELECT * FROM srv_data_text_archive2 WHERE spr_id IN (".$qry_cache_spr_id.")", self :: $src_connect_db);
+ $arr_src['srv_data_text_archive2'] = self::sql2array($qry_src_data_text_archive2);
+
+ $qry_src_data_text_archive3 = sisplet_query("SELECT * FROM srv_data_text_archive3 WHERE spr_id IN (".$qry_cache_spr_id.")", self :: $src_connect_db);
+ $arr_src['srv_data_text_archive3'] = self::sql2array($qry_src_data_text_archive3);
$qry_src_data_text_active = sisplet_query("SELECT * FROM srv_data_text_active WHERE spr_id IN (".$qry_cache_spr_id.")", self :: $src_connect_db);
$arr_src['srv_data_text_active'] = self::sql2array($qry_src_data_text_active);
- $qry_src_data_textgrid = sisplet_query("SELECT * FROM srv_data_textgrid WHERE spr_id IN (".$qry_cache_spr_id.")", self :: $src_connect_db);
- $arr_src['srv_data_textgrid'] = self::sql2array($qry_src_data_textgrid);
+ $qry_src_data_textgrid_archive1 = sisplet_query("SELECT * FROM srv_data_textgrid_archive1 WHERE spr_id IN (".$qry_cache_spr_id.")", self :: $src_connect_db);
+ $arr_src['srv_data_textgrid_archive1'] = self::sql2array($qry_src_data_textgrid_archive1);
+
+ $qry_src_data_textgrid_archive2 = sisplet_query("SELECT * FROM srv_data_textgrid_archive2 WHERE spr_id IN (".$qry_cache_spr_id.")", self :: $src_connect_db);
+ $arr_src['srv_data_textgrid_archive2'] = self::sql2array($qry_src_data_textgrid_archive2);
+
+ $qry_src_data_textgrid_archive3 = sisplet_query("SELECT * FROM srv_data_textgrid_archive3 WHERE spr_id IN (".$qry_cache_spr_id.")", self :: $src_connect_db);
+ $arr_src['srv_data_textgrid_archive3'] = self::sql2array($qry_src_data_textgrid_archive3);
$qry_src_data_textgrid_active = sisplet_query("SELECT * FROM srv_data_textgrid_active WHERE spr_id IN (".$qry_cache_spr_id.")", self :: $src_connect_db);
$arr_src['srv_data_textgrid_active'] = self::sql2array($qry_src_data_textgrid_active);
@@ -413,14 +447,26 @@ class SurveyCopy {
$qry_src_data_upload = sisplet_query("SELECT * FROM srv_data_upload WHERE ank_id='".self::$src_survey."'", self :: $src_connect_db);
$arr_src['srv_data_upload'] = self::sql2array($qry_src_data_upload);
- $qry_src_data_vrednost = sisplet_query("SELECT * FROM srv_data_vrednost WHERE spr_id IN (".$qry_cache_spr_id.")", self :: $src_connect_db);
- $arr_src['srv_data_vrednost'] = self::sql2array($qry_src_data_vrednost);
+ $qry_src_data_vrednost_archive1 = sisplet_query("SELECT * FROM srv_data_vrednost_archive1 WHERE spr_id IN (".$qry_cache_spr_id.")", self :: $src_connect_db);
+ $arr_src['srv_data_vrednost_archive1'] = self::sql2array($qry_src_data_vrednost_archive1);
+
+ $qry_src_data_vrednost_archive2 = sisplet_query("SELECT * FROM srv_data_vrednost_archive2 WHERE spr_id IN (".$qry_cache_spr_id.")", self :: $src_connect_db);
+ $arr_src['srv_data_vrednost_archive2'] = self::sql2array($qry_src_data_vrednost_archive2);
+
+ $qry_src_data_vrednost_archive3 = sisplet_query("SELECT * FROM srv_data_vrednost_archive3 WHERE spr_id IN (".$qry_cache_spr_id.")", self :: $src_connect_db);
+ $arr_src['srv_data_vrednost_archive3'] = self::sql2array($qry_src_data_vrednost_archive3);
$qry_src_data_vrednost_active = sisplet_query("SELECT * FROM srv_data_vrednost_active WHERE spr_id IN (".$qry_cache_spr_id.")", self :: $src_connect_db);
$arr_src['srv_data_vrednost_active'] = self::sql2array($qry_src_data_vrednost_active);
- $qry_src_user_grupa = sisplet_query("SELECT * FROM srv_user_grupa WHERE usr_id IN (".$qry_cache_usr_id.")", self::$src_connect_db);
- $arr_src['srv_user_grupa'] = self::sql2array($qry_src_user_grupa);
+ $qry_src_user_grupa_archive1 = sisplet_query("SELECT * FROM srv_user_grupa_archive1 WHERE usr_id IN (".$qry_cache_usr_id.")", self::$src_connect_db);
+ $arr_src['srv_user_grupa_archive1'] = self::sql2array($qry_src_user_grupa_archive1);
+
+ $qry_src_user_grupa_archive2 = sisplet_query("SELECT * FROM srv_user_grupa_archive2 WHERE usr_id IN (".$qry_cache_usr_id.")", self::$src_connect_db);
+ $arr_src['srv_user_grupa_archive2'] = self::sql2array($qry_src_user_grupa_archive2);
+
+ $qry_src_user_grupa_archive3 = sisplet_query("SELECT * FROM srv_user_grupa_archive3 WHERE usr_id IN (".$qry_cache_usr_id.")", self::$src_connect_db);
+ $arr_src['srv_user_grupa_archive3'] = self::sql2array($qry_src_user_grupa_archive3);
$qry_src_user_grupa_active = sisplet_query("SELECT * FROM srv_user_grupa_active WHERE usr_id IN (".$qry_cache_usr_id.")", self::$src_connect_db);
$arr_src['srv_user_grupa_active'] = self::sql2array($qry_src_user_grupa_active);
@@ -473,8 +519,12 @@ class SurveyCopy {
// iz izvorne ankete preberemo vsa polja
if ( count($arr_src['srv_anketa']) > 0) {
+ // Nastavimo se hash nove ankete
+ $hash = Common::generateSurveyHash();
+
// predefinirana polja (vsilimo vrednosti)
$pre_set = array('id' => "NULL",
+ 'hash' => "'".$hash."'",
'backup' => "'0'",
'active' => "'0'",
'locked' => "'0'",
@@ -603,7 +653,7 @@ class SurveyCopy {
$new_grupa_ids[0] = 0; // pri srv_user_grupa je 0 za prvo stran
$new_spremenljivke_ids = array();
- if (count($new_grupa_ids) > 0) {
+ if (is_countable($new_grupa_ids) && count($new_grupa_ids) > 0) {
foreach ($new_grupa_ids as $old_grupa_id => $new_grupa_id) {
// spremenljivke, tabela srv_spremenljivka
@@ -625,7 +675,7 @@ class SurveyCopy {
// gridi - srv_grid
$new_grid_ids = array();
- if (count($new_spremenljivke_ids) > 0) {
+ if (is_countable($new_spremenljivke_ids) && count($new_spremenljivke_ids) > 0) {
foreach ($new_spremenljivke_ids AS $old_spremenljivka_id => $new_spremenljivka_id) {
// gridi, tabela srv_grid
@@ -634,7 +684,7 @@ class SurveyCopy {
$tmp_grid_ids = self :: preformCopyTable('srv_grid', 'variable', $src_srv_grid, $pre_set);
// shranimo stare in nove id-je spremenljivk
- if ( count($tmp_grid_ids) > 0 )
+ if ($tmp_grid_ids !=null && count($tmp_grid_ids) > 0 )
foreach ($tmp_grid_ids as $key => $value)
$new_grid_ids[$new_spremenljivka_id][$key] = $value;
@@ -664,28 +714,6 @@ class SurveyCopy {
$pre_set = array('sid' => "'".$new_survey_id."'");
$new_missing_values_ids = self::preformCopyTable('srv_missing_values', null, $arr_src['srv_missing_values'], $pre_set);
-
- // vrednosti - prestavljeno pod srv_if da se ne porusijo notranji pogoji! Patrik - zakaj je bilo to prestavljeno višje??
- /*$new_vrednosti_ids = array();
- if ( count($new_spremenljivke_ids) > 0) {
- foreach( $new_spremenljivke_ids AS $old_spremenljivka_id => $new_spremenljivka_id) {
-
- // vrednosti, tabela srv_vrednost
- $src_srv_vrednost = self::arrayfilter($arr_src['srv_vrednost'], 'spr_id', $old_spremenljivka_id);
- $pre_set = array('id' => "NULL",
- 'spr_id' => array('field'=>'spr_id', 'from'=>$new_spremenljivke_ids),
- 'vre_id' => array('field'=>'vre_id', 'from'=>$new_vrednosti_ids));
- $tmp_vrednosti_ids = self :: preformCopyTable('srv_vrednost', 'id', $src_srv_vrednost, $pre_set);
-
- // shranimo stare in nove id-je spremenljivk
- if ( count($tmp_vrednosti_ids) > 0 )
-
- foreach ($tmp_vrednosti_ids as $key => $value){
- $new_vrednosti_ids[$key] = $value;
- }
- }
- }*/
-
// splosne nastavitve ankete, tabela srv_survey_misc
$pre_set = array('sid' => "'".$new_survey_id."'");
@@ -705,7 +733,6 @@ class SurveyCopy {
foreach ($srv_if AS $row) {
// IF-i, tabela srv_if
- //$qry_src_if = sisplet_query("SELECT * FROM srv_if WHERE id = '".$row[id]."'", self :: $src_connect_db);
$qry_src_if = self::arrayfilter($arr_src['srv_if'], 'id', $row['id']);
$pre_set = array('id' => "NULL");
$tmp_if_ids = self :: preformCopyTable('srv_if', 'id', $qry_src_if, $pre_set);
@@ -715,7 +742,7 @@ class SurveyCopy {
// vrednosti
$new_vrednosti_ids = array();
- if ( count($new_spremenljivke_ids) > 0) {
+ if (is_countable($new_spremenljivke_ids) && count($new_spremenljivke_ids) > 0) {
foreach( $new_spremenljivke_ids AS $old_spremenljivka_id => $new_spremenljivka_id) {
// vrednosti, tabela srv_vrednost
@@ -726,7 +753,7 @@ class SurveyCopy {
$tmp_vrednosti_ids = self :: preformCopyTable('srv_vrednost', 'id', $src_srv_vrednost, $pre_set);
// shranimo stare in nove id-je spremenljivk
- if ( count($tmp_vrednosti_ids) > 0 )
+ if ( is_countable($tmp_vrednosti_ids) && count($tmp_vrednosti_ids) > 0 )
foreach ($tmp_vrednosti_ids as $key => $value)
$new_vrednosti_ids[$key] = $value;
@@ -736,7 +763,7 @@ class SurveyCopy {
// srv_calculation
// za vsak condition , če je spr_id > 0 priredimo novo, če ne damo enako (-1,-2)
- if (count($new_spremenljivke_ids) > 0) {
+ if (is_countable($new_spremenljivke_ids) && count($new_spremenljivke_ids) > 0) {
foreach ($new_spremenljivke_ids AS $old_spremenljivka_id => $new_spremenljivka_id) {
$srv_calculation = self::arrayfilter($arr_src['srv_calculation'], 'cnd_id', -$old_spremenljivka_id);
@@ -790,7 +817,7 @@ class SurveyCopy {
// condtition grid, tabela srv_condition_grid
- if (count($condition) > 0) {
+ if (is_countable($condition) && count($condition) > 0) {
foreach ($condition AS $orig => $bckp) {
// condtition grid, tabela srv_condition_grid
//$qry_src_condition_grid = sisplet_query("SELECT * FROM srv_condition_grid WHERE cond_id = '".$orig."'", self :: $src_connect_db);
@@ -803,7 +830,7 @@ class SurveyCopy {
}
// condtition vrednost, tabela srv_condition_vre
- if (count($condition) > 0) {
+ if (is_countable($condition) && count($condition) > 0) {
foreach ($condition AS $orig => $bckp) {
//$qry_src_condition_vre = sisplet_query("SELECT * FROM srv_condition_vre WHERE cond_id = '$orig'", self :: $src_connect_db);
$src_srv_condition_vre = self::arrayfilter($arr_src['srv_condition_vre'], 'cond_id', $orig);
@@ -843,7 +870,7 @@ class SurveyCopy {
// srv_calculation
// za vsak condition , če je spr_id > 0 priredimo novo, če ne damo enako (-1,-2)
- if (count($condition) > 0) {
+ if (is_countable($condition) && count($condition) > 0) {
foreach ($condition AS $orig => $bckp) {
//$qry_src_calculation = sisplet_query("SELECT * FROM srv_calculation WHERE cnd_id = '$orig'", self :: $src_connect_db);
$src_srv_calculation = self::arrayfilter($arr_src['srv_calculation'], 'cnd_id', $orig);
@@ -889,7 +916,7 @@ class SurveyCopy {
/**
* PODATKI
*/
- if ( $arr_src['data'] ) {
+ if ( isset($arr_src['data']) ) {
$ip = GetIP();
// srv_user
@@ -907,18 +934,34 @@ class SurveyCopy {
'ank_id' => "'".$new_survey_id."'");
$src_srv_user = self::arrayfilter($arr_src['srv_user'], 'id', $row_array['id']);
$tmp_user_ids = self::preformCopyTable('srv_user', 'id', $src_srv_user, $pre_set);
- if ( count($tmp_user_ids) > 0 )
+ if ( is_countable($tmp_user_ids) && count($tmp_user_ids) > 0 )
foreach ($tmp_user_ids as $key => $value)
$new_user_ids[$key] = $value;
}
- // srv_data_checkgrid - VSE VEDNO KOPIRAMO V ACTIVE TABELE
+ // srv_data_checkgrid_archive1 - VSE VEDNO KOPIRAMO V ACTIVE TABELE
$pre_set = array('spr_id' => array('field'=>'spr_id', 'from' => $new_spremenljivke_ids),
'vre_id' => array('field'=>'vre_id', 'from' => $new_vrednosti_ids),
'usr_id' => array('field'=>'usr_id', 'from' => $new_user_ids),
'grd_id' => array('field'=>'grd_id', 'from' => $new_grid_ids),
'loop_id' => array('field'=>'loop_id', 'from' => $new_loop_data_ids));
- self::preformCopyTable('srv_data_checkgrid_active', null, $arr_src['srv_data_checkgrid'], $pre_set);
+ self::preformCopyTable('srv_data_checkgrid_active', null, $arr_src['srv_data_checkgrid_archive1'], $pre_set);
+
+ // srv_data_checkgrid_archive2 - VSE VEDNO KOPIRAMO V ACTIVE TABELE
+ $pre_set = array('spr_id' => array('field'=>'spr_id', 'from' => $new_spremenljivke_ids),
+ 'vre_id' => array('field'=>'vre_id', 'from' => $new_vrednosti_ids),
+ 'usr_id' => array('field'=>'usr_id', 'from' => $new_user_ids),
+ 'grd_id' => array('field'=>'grd_id', 'from' => $new_grid_ids),
+ 'loop_id' => array('field'=>'loop_id', 'from' => $new_loop_data_ids));
+ self::preformCopyTable('srv_data_checkgrid_active', null, $arr_src['srv_data_checkgrid_archive2'], $pre_set);
+
+ // srv_data_checkgrid_archive3 - VSE VEDNO KOPIRAMO V ACTIVE TABELE
+ $pre_set = array('spr_id' => array('field'=>'spr_id', 'from' => $new_spremenljivke_ids),
+ 'vre_id' => array('field'=>'vre_id', 'from' => $new_vrednosti_ids),
+ 'usr_id' => array('field'=>'usr_id', 'from' => $new_user_ids),
+ 'grd_id' => array('field'=>'grd_id', 'from' => $new_grid_ids),
+ 'loop_id' => array('field'=>'loop_id', 'from' => $new_loop_data_ids));
+ self::preformCopyTable('srv_data_checkgrid_active', null, $arr_src['srv_data_checkgrid_archive3'], $pre_set);
// srv_data_checkgrid_active
$pre_set = array('spr_id' => array('field'=>'spr_id', 'from' => $new_spremenljivke_ids),
@@ -933,13 +976,29 @@ class SurveyCopy {
'usr_id' => array('field'=>'usr_id', 'from' => $new_user_ids));
self::preformCopyTable('srv_data_glasovanje', null, $arr_src['srv_data_glasovanje'], $pre_set);
- // srv_data_grid - VSE VEDNO KOPIRAMO V ACTIVE TABELE
+ // srv_data_grid_archive1 - VSE VEDNO KOPIRAMO V ACTIVE TABELE
+ $pre_set = array('spr_id' => array('field'=>'spr_id', 'from' => $new_spremenljivke_ids),
+ 'vre_id' => array('field'=>'vre_id', 'from' => $new_vrednosti_ids),
+ 'usr_id' => array('field'=>'usr_id', 'from' => $new_user_ids),
+ 'grd_id' => array('field'=>'grd_id', 'from' => $new_grid_ids),
+ 'loop_id' => array('field'=>'loop_id', 'from' => $new_loop_data_ids));
+ self::preformCopyTable('srv_data_grid_active', null, $arr_src['srv_data_grid_archive1'], $pre_set);
+
+ // srv_data_grid_archive2 - VSE VEDNO KOPIRAMO V ACTIVE TABELE
+ $pre_set = array('spr_id' => array('field'=>'spr_id', 'from' => $new_spremenljivke_ids),
+ 'vre_id' => array('field'=>'vre_id', 'from' => $new_vrednosti_ids),
+ 'usr_id' => array('field'=>'usr_id', 'from' => $new_user_ids),
+ 'grd_id' => array('field'=>'grd_id', 'from' => $new_grid_ids),
+ 'loop_id' => array('field'=>'loop_id', 'from' => $new_loop_data_ids));
+ self::preformCopyTable('srv_data_grid_active', null, $arr_src['srv_data_grid_archive2'], $pre_set);
+
+ // srv_data_grid_archive3 - VSE VEDNO KOPIRAMO V ACTIVE TABELE
$pre_set = array('spr_id' => array('field'=>'spr_id', 'from' => $new_spremenljivke_ids),
'vre_id' => array('field'=>'vre_id', 'from' => $new_vrednosti_ids),
'usr_id' => array('field'=>'usr_id', 'from' => $new_user_ids),
'grd_id' => array('field'=>'grd_id', 'from' => $new_grid_ids),
'loop_id' => array('field'=>'loop_id', 'from' => $new_loop_data_ids));
- self::preformCopyTable('srv_data_grid_active', null, $arr_src['srv_data_grid'], $pre_set);
+ self::preformCopyTable('srv_data_grid_active', null, $arr_src['srv_data_grid_archive3'], $pre_set);
// srv_data_grid_active
$pre_set = array('spr_id' => array('field'=>'spr_id', 'from' => $new_spremenljivke_ids),
@@ -956,13 +1015,29 @@ class SurveyCopy {
'loop_id' => array('field'=>'loop_id', 'from' => $new_loop_data_ids));
self::preformCopyTable('srv_data_rating', null, $arr_src['srv_data_rating'], $pre_set);
- // srv_data_text - VSE VEDNO KOPIRAMO V ACTIVE TABELE
+ // srv_data_text_archive1 - VSE VEDNO KOPIRAMO V ACTIVE TABELE
$pre_set = array('id' => "NULL",
'spr_id' => array('field'=>'spr_id', 'from' => $new_spremenljivke_ids),
'vre_id' => array('field'=>'vre_id', 'from' => $new_vrednosti_ids),
'usr_id' => array('field'=>'usr_id', 'from' => $new_user_ids),
'loop_id' => array('field'=>'loop_id', 'from' => $new_loop_data_ids));
- self::preformCopyTable('srv_data_text_active', 'id', $arr_src['srv_data_text'], $pre_set);
+ self::preformCopyTable('srv_data_text_active', 'id', $arr_src['srv_data_text_archive1'], $pre_set);
+
+ // srv_data_text_archive2 - VSE VEDNO KOPIRAMO V ACTIVE TABELE
+ $pre_set = array('id' => "NULL",
+ 'spr_id' => array('field'=>'spr_id', 'from' => $new_spremenljivke_ids),
+ 'vre_id' => array('field'=>'vre_id', 'from' => $new_vrednosti_ids),
+ 'usr_id' => array('field'=>'usr_id', 'from' => $new_user_ids),
+ 'loop_id' => array('field'=>'loop_id', 'from' => $new_loop_data_ids));
+ self::preformCopyTable('srv_data_text_active', 'id', $arr_src['srv_data_text_archive2'], $pre_set);
+
+ // srv_data_text_archive3 - VSE VEDNO KOPIRAMO V ACTIVE TABELE
+ $pre_set = array('id' => "NULL",
+ 'spr_id' => array('field'=>'spr_id', 'from' => $new_spremenljivke_ids),
+ 'vre_id' => array('field'=>'vre_id', 'from' => $new_vrednosti_ids),
+ 'usr_id' => array('field'=>'usr_id', 'from' => $new_user_ids),
+ 'loop_id' => array('field'=>'loop_id', 'from' => $new_loop_data_ids));
+ self::preformCopyTable('srv_data_text_active', 'id', $arr_src['srv_data_text_archive3'], $pre_set);
// srv_data_text_active
$pre_set = array('id' => "NULL",
@@ -972,13 +1047,29 @@ class SurveyCopy {
'loop_id' => array('field'=>'loop_id', 'from' => $new_loop_data_ids));
self::preformCopyTable('srv_data_text_active', 'id', $arr_src['srv_data_text_active'], $pre_set);
- // srv_data_textgrid - VSE VEDNO KOPIRAMO V ACTIVE TABELE
+ // srv_data_textgrid_archive1 - VSE VEDNO KOPIRAMO V ACTIVE TABELE
$pre_set = array('spr_id' => array('field'=>'spr_id', 'from' => $new_spremenljivke_ids),
'vre_id' => array('field'=>'vre_id', 'from' => $new_vrednosti_ids),
'usr_id' => array('field'=>'usr_id', 'from' => $new_user_ids),
'grd_id' => array('field'=>'grd_id', 'from' => $new_grid_ids),
'loop_id' => array('field'=>'loop_id', 'from' => $new_loop_data_ids));
- self::preformCopyTable('srv_data_textgrid_active', null, $arr_src['srv_data_textgrid'], $pre_set);
+ self::preformCopyTable('srv_data_textgrid_active', null, $arr_src['srv_data_textgrid_archive1'], $pre_set);
+
+ // srv_data_textgrid_archive2 - VSE VEDNO KOPIRAMO V ACTIVE TABELE
+ $pre_set = array('spr_id' => array('field'=>'spr_id', 'from' => $new_spremenljivke_ids),
+ 'vre_id' => array('field'=>'vre_id', 'from' => $new_vrednosti_ids),
+ 'usr_id' => array('field'=>'usr_id', 'from' => $new_user_ids),
+ 'grd_id' => array('field'=>'grd_id', 'from' => $new_grid_ids),
+ 'loop_id' => array('field'=>'loop_id', 'from' => $new_loop_data_ids));
+ self::preformCopyTable('srv_data_textgrid_active', null, $arr_src['srv_data_textgrid_archive2'], $pre_set);
+
+ // srv_data_textgrid_archive3 - VSE VEDNO KOPIRAMO V ACTIVE TABELE
+ $pre_set = array('spr_id' => array('field'=>'spr_id', 'from' => $new_spremenljivke_ids),
+ 'vre_id' => array('field'=>'vre_id', 'from' => $new_vrednosti_ids),
+ 'usr_id' => array('field'=>'usr_id', 'from' => $new_user_ids),
+ 'grd_id' => array('field'=>'grd_id', 'from' => $new_grid_ids),
+ 'loop_id' => array('field'=>'loop_id', 'from' => $new_loop_data_ids));
+ self::preformCopyTable('srv_data_textgrid_active', null, $arr_src['srv_data_textgrid_archive3'], $pre_set);
// srv_data_textgrid_active
$pre_set = array('spr_id' => array('field'=>'spr_id', 'from' => $new_spremenljivke_ids),
@@ -993,12 +1084,26 @@ class SurveyCopy {
'usr_id' => array('field'=>'usr_id', 'from' => $new_user_ids));
self::preformCopyTable('srv_data_upload', null, $arr_src['srv_data_upload'], $pre_set);
- // srv_data_vrednost - VSE VEDNO KOPIRAMO V ACTIVE TABELE
+ // srv_data_vrednost_archive1 - VSE VEDNO KOPIRAMO V ACTIVE TABELE
+ $pre_set = array('spr_id' => array('field'=>'spr_id', 'from' => $new_spremenljivke_ids),
+ 'vre_id' => array('field'=>'vre_id', 'from' => $new_vrednosti_ids),
+ 'usr_id' => array('field'=>'usr_id', 'from' => $new_user_ids),
+ 'loop_id' => array('field'=>'loop_id', 'from' => $new_loop_data_ids));
+ self::preformCopyTable('srv_data_vrednost_active', null, $arr_src['srv_data_vrednost_archive1'], $pre_set);
+
+ // srv_data_vrednost_archive2 - VSE VEDNO KOPIRAMO V ACTIVE TABELE
+ $pre_set = array('spr_id' => array('field'=>'spr_id', 'from' => $new_spremenljivke_ids),
+ 'vre_id' => array('field'=>'vre_id', 'from' => $new_vrednosti_ids),
+ 'usr_id' => array('field'=>'usr_id', 'from' => $new_user_ids),
+ 'loop_id' => array('field'=>'loop_id', 'from' => $new_loop_data_ids));
+ self::preformCopyTable('srv_data_vrednost_active', null, $arr_src['srv_data_vrednost_archive2'], $pre_set);
+
+ // srv_data_vrednost_archive3 - VSE VEDNO KOPIRAMO V ACTIVE TABELE
$pre_set = array('spr_id' => array('field'=>'spr_id', 'from' => $new_spremenljivke_ids),
'vre_id' => array('field'=>'vre_id', 'from' => $new_vrednosti_ids),
'usr_id' => array('field'=>'usr_id', 'from' => $new_user_ids),
'loop_id' => array('field'=>'loop_id', 'from' => $new_loop_data_ids));
- self::preformCopyTable('srv_data_vrednost_active', null, $arr_src['srv_data_vrednost'], $pre_set);
+ self::preformCopyTable('srv_data_vrednost_active', null, $arr_src['srv_data_vrednost_archive3'], $pre_set);
// srv_data_vrednost_active
$pre_set = array('spr_id' => array('field'=>'spr_id', 'from' => $new_spremenljivke_ids),
@@ -1007,10 +1112,20 @@ class SurveyCopy {
'loop_id' => array('field'=>'loop_id', 'from' => $new_loop_data_ids));
self::preformCopyTable('srv_data_vrednost_active', null, $arr_src['srv_data_vrednost_active'], $pre_set);
- // srv_user_grupa - VSE VEDNO KOPIRAMO V ACTIVE TABELE
+ // srv_user_grupa_archive1 - VSE VEDNO KOPIRAMO V ACTIVE TABELE
+ $pre_set = array('gru_id' => array('field'=>'gru_id', 'from' => $new_grupa_ids),
+ 'usr_id' => array('field'=>'usr_id', 'from' => $new_user_ids));
+ self::preformCopyTable('srv_user_grupa_active', null, $arr_src['srv_user_grupa_archive1'], $pre_set);
+
+ // srv_user_grupa_archive2 - VSE VEDNO KOPIRAMO V ACTIVE TABELE
$pre_set = array('gru_id' => array('field'=>'gru_id', 'from' => $new_grupa_ids),
'usr_id' => array('field'=>'usr_id', 'from' => $new_user_ids));
- self::preformCopyTable('srv_user_grupa_active', null, $arr_src['srv_user_grupa'], $pre_set);
+ self::preformCopyTable('srv_user_grupa_active', null, $arr_src['srv_user_grupa_archive2'], $pre_set);
+
+ // srv_user_grupa_archive3 - VSE VEDNO KOPIRAMO V ACTIVE TABELE
+ $pre_set = array('gru_id' => array('field'=>'gru_id', 'from' => $new_grupa_ids),
+ 'usr_id' => array('field'=>'usr_id', 'from' => $new_user_ids));
+ self::preformCopyTable('srv_user_grupa_active', null, $arr_src['srv_user_grupa_archive3'], $pre_set);
// srv_user_grupa_active
$pre_set = array('gru_id' => array('field'=>'gru_id', 'from' => $new_grupa_ids),
@@ -1077,7 +1192,7 @@ class SurveyCopy {
self :: $errors[] = 'Could not run query: ' . mysqli_error($GLOBALS['connect_db']);
}
- if ( count($array_source) > 0 ) {
+ if (is_countable($array_source) && count($array_source) > 0) {
// zloopamo skozi polja druge tabele in predpripravimo insert string polja
if (mysqli_num_rows($dest_table_fields) > 0) {
@@ -1115,15 +1230,15 @@ class SurveyCopy {
*/
// ce polje v src datoteki ni nastavljeno ga damo na praznega
- if ( ! isset($row_src[$dest_field]) && ! isset($pre_set[$dest_field]) ) {
- $dest_value = "''";
-
- // ce je polje NULL, ga moramo rocno nastavit na NULL
- } elseif ($row_src[$dest_field] === NULL) {
- $dest_value = "NULL";
-
- } else {
-
+ if ( !isset($row_src[$dest_field]) && !isset($pre_set[$dest_field]) ) {
+ $dest_value = "''";
+ }
+ // ce je polje NULL, ga moramo rocno nastavit na NULL
+ //elseif ( $row_src[$dest_field] === NULL && !isset($pre_set[$dest_field]) ) { // Ce potrebujemo kompatibilnost za nazaj se lahko to vklopi
+ elseif ( $row_src[$dest_field] === NULL ) {
+ $dest_value = "NULL";
+ }
+ else {
$dest_value = isset($pre_set[$dest_field])
? ( !(is_array($pre_set[$dest_field]) && isset($pre_set[$dest_field]['field']) && isset($pre_set[$dest_field]['from']))
? $pre_set[$dest_field]
@@ -1133,7 +1248,6 @@ class SurveyCopy {
)
)
: "'".mysqli_real_escape_string($GLOBALS['connect_db'], $row_src[$dest_field])."'";
-
}
$insert_values .= $insert_values_prefix . $dest_value;
@@ -1159,7 +1273,9 @@ class SurveyCopy {
}
} else {
// lahko da je sql ne vrne id-ja (kadar ni primary key-a)
- $result[$row_src[$id_field]] = $row_src[$id_field];
+ if (isset($row_src[$id_field])) {
+ $result[$row_src[$id_field]] = $row_src[$id_field];
+ }
}
}
@@ -1223,11 +1339,23 @@ class SurveyCopy {
// Kopiramo odgovore
- // srv_data_vrednost
- $sqlD = sisplet_query("SELECT * FROM srv_data_vrednost WHERE usr_id='".$usr_id."'");
+ // srv_data_vrednost_archive1
+ $sqlD = sisplet_query("SELECT * FROM srv_data_vrednost_archive1 WHERE usr_id='".$usr_id."'");
+ $pre_set = array( 'usr_id' => $new_usr_id,
+ 'loop_id' => "NULL");
+ self::preformCopyTable('srv_data_vrednost_archive1', null, self::sql2array($sqlD), $pre_set);
+
+ // srv_data_vrednost_archive2
+ $sqlD = sisplet_query("SELECT * FROM srv_data_vrednost_archive2 WHERE usr_id='".$usr_id."'");
+ $pre_set = array( 'usr_id' => $new_usr_id,
+ 'loop_id' => "NULL");
+ self::preformCopyTable('srv_data_vrednost_archive2', null, self::sql2array($sqlD), $pre_set);
+
+ // srv_data_vrednost_archive3
+ $sqlD = sisplet_query("SELECT * FROM srv_data_vrednost_archive3 WHERE usr_id='".$usr_id."'");
$pre_set = array( 'usr_id' => $new_usr_id,
'loop_id' => "NULL");
- self::preformCopyTable('srv_data_vrednost', null, self::sql2array($sqlD), $pre_set);
+ self::preformCopyTable('srv_data_vrednost_archive3', null, self::sql2array($sqlD), $pre_set);
// srv_data_vrednost_active
$sqlD = sisplet_query("SELECT * FROM srv_data_vrednost_active WHERE usr_id='".$usr_id."'");
@@ -1235,12 +1363,26 @@ class SurveyCopy {
'loop_id' => "NULL");
self::preformCopyTable('srv_data_vrednost_active', null, self::sql2array($sqlD), $pre_set);
- // srv_data_text
- $sqlD = sisplet_query("SELECT * FROM srv_data_text WHERE usr_id='".$usr_id."'");
+ // srv_data_text_archive1
+ $sqlD = sisplet_query("SELECT * FROM srv_data_text_archive1 WHERE usr_id='".$usr_id."'");
$pre_set = array( 'id' => "NULL",
'usr_id' => $new_usr_id,
'loop_id' => "NULL");
- self::preformCopyTable('srv_data_text', 'id', self::sql2array($sqlD), $pre_set);
+ self::preformCopyTable('srv_data_text_archive1', 'id', self::sql2array($sqlD), $pre_set);
+
+ // srv_data_text_archive2
+ $sqlD = sisplet_query("SELECT * FROM srv_data_text_archive2 WHERE usr_id='".$usr_id."'");
+ $pre_set = array( 'id' => "NULL",
+ 'usr_id' => $new_usr_id,
+ 'loop_id' => "NULL");
+ self::preformCopyTable('srv_data_text_archive2', 'id', self::sql2array($sqlD), $pre_set);
+
+ // srv_data_text_archive3
+ $sqlD = sisplet_query("SELECT * FROM srv_data_text_archive3 WHERE usr_id='".$usr_id."'");
+ $pre_set = array( 'id' => "NULL",
+ 'usr_id' => $new_usr_id,
+ 'loop_id' => "NULL");
+ self::preformCopyTable('srv_data_text_archive3', 'id', self::sql2array($sqlD), $pre_set);
// srv_data_text_active
$sqlD = sisplet_query("SELECT * FROM srv_data_text_active WHERE usr_id='".$usr_id."'");
@@ -1249,11 +1391,23 @@ class SurveyCopy {
'loop_id' => "NULL");
self::preformCopyTable('srv_data_text_active', 'id', self::sql2array($sqlD), $pre_set);
- // srv_data_checkgrid
- $sqlD = sisplet_query("SELECT * FROM srv_data_checkgrid WHERE usr_id='".$usr_id."'");
+ // srv_data_checkgrid_archive1
+ $sqlD = sisplet_query("SELECT * FROM srv_data_checkgrid_archive1 WHERE usr_id='".$usr_id."'");
+ $pre_set = array( 'usr_id' => $new_usr_id,
+ 'loop_id' => "NULL");
+ self::preformCopyTable('srv_data_checkgrid_archive1', null, self::sql2array($sqlD), $pre_set);
+
+ // srv_data_checkgrid_archive2
+ $sqlD = sisplet_query("SELECT * FROM srv_data_checkgrid_archive2 WHERE usr_id='".$usr_id."'");
$pre_set = array( 'usr_id' => $new_usr_id,
'loop_id' => "NULL");
- self::preformCopyTable('srv_data_checkgrid', null, self::sql2array($sqlD), $pre_set);
+ self::preformCopyTable('srv_data_checkgrid_archive2', null, self::sql2array($sqlD), $pre_set);
+
+ // srv_data_checkgrid_archive3
+ $sqlD = sisplet_query("SELECT * FROM srv_data_checkgrid_archive3 WHERE usr_id='".$usr_id."'");
+ $pre_set = array( 'usr_id' => $new_usr_id,
+ 'loop_id' => "NULL");
+ self::preformCopyTable('srv_data_checkgrid_archive3', null, self::sql2array($sqlD), $pre_set);
// srv_data_checkgrid_active
$sqlD = sisplet_query("SELECT * FROM srv_data_checkgrid_active WHERE usr_id='".$usr_id."'");
@@ -1261,11 +1415,23 @@ class SurveyCopy {
'loop_id' => "NULL");
self::preformCopyTable('srv_data_checkgrid_active', null, self::sql2array($sqlD), $pre_set);
- // srv_data_grid
- $sqlD = sisplet_query("SELECT * FROM srv_data_grid WHERE usr_id='".$usr_id."'");
+ // srv_data_grid_archive1
+ $sqlD = sisplet_query("SELECT * FROM srv_data_grid_archive1 WHERE usr_id='".$usr_id."'");
+ $pre_set = array( 'usr_id' => $new_usr_id,
+ 'loop_id' => "NULL");
+ self::preformCopyTable('srv_data_grid_archive1', null, self::sql2array($sqlD), $pre_set);
+
+ // srv_data_grid_archive2
+ $sqlD = sisplet_query("SELECT * FROM srv_data_grid_archive2 WHERE usr_id='".$usr_id."'");
$pre_set = array( 'usr_id' => $new_usr_id,
'loop_id' => "NULL");
- self::preformCopyTable('srv_data_grid', null, self::sql2array($sqlD), $pre_set);
+ self::preformCopyTable('srv_data_grid_archive2', null, self::sql2array($sqlD), $pre_set);
+
+ // srv_data_grid_archive3
+ $sqlD = sisplet_query("SELECT * FROM srv_data_grid_archive3 WHERE usr_id='".$usr_id."'");
+ $pre_set = array( 'usr_id' => $new_usr_id,
+ 'loop_id' => "NULL");
+ self::preformCopyTable('srv_data_grid_archive3', null, self::sql2array($sqlD), $pre_set);
// srv_data_grid_active
$sqlD = sisplet_query("SELECT * FROM srv_data_grid_active WHERE usr_id='".$usr_id."'");
@@ -1273,11 +1439,23 @@ class SurveyCopy {
'loop_id' => "NULL");
self::preformCopyTable('srv_data_grid_active', null, self::sql2array($sqlD), $pre_set);
- // srv_data_textgrid
- $sqlD = sisplet_query("SELECT * FROM srv_data_textgrid WHERE usr_id='".$usr_id."'");
+ // srv_data_textgrid_archive1
+ $sqlD = sisplet_query("SELECT * FROM srv_data_textgrid_archive1 WHERE usr_id='".$usr_id."'");
$pre_set = array( 'usr_id' => $new_usr_id,
'loop_id' => "NULL");
- self::preformCopyTable('srv_data_textgrid', null, self::sql2array($sqlD), $pre_set);
+ self::preformCopyTable('srv_data_textgrid_archive1', null, self::sql2array($sqlD), $pre_set);
+
+ // srv_data_textgrid_archive2
+ $sqlD = sisplet_query("SELECT * FROM srv_data_textgrid_archive2 WHERE usr_id='".$usr_id."'");
+ $pre_set = array( 'usr_id' => $new_usr_id,
+ 'loop_id' => "NULL");
+ self::preformCopyTable('srv_data_textgrid_archive2', null, self::sql2array($sqlD), $pre_set);
+
+ // srv_data_textgrid_archive3
+ $sqlD = sisplet_query("SELECT * FROM srv_data_textgrid_archive3 WHERE usr_id='".$usr_id."'");
+ $pre_set = array( 'usr_id' => $new_usr_id,
+ 'loop_id' => "NULL");
+ self::preformCopyTable('srv_data_textgrid_archive3', null, self::sql2array($sqlD), $pre_set);
// srv_data_textgrid_active
$sqlD = sisplet_query("SELECT * FROM srv_data_textgrid_active WHERE usr_id='".$usr_id."'");
@@ -1301,11 +1479,23 @@ class SurveyCopy {
$pre_set = array( 'usr_id' => $new_usr_id);
self::preformCopyTable('srv_data_glasovanje', null, self::sql2array($sqlD), $pre_set);
- // srv_user_grupa
- $sqlD = sisplet_query("SELECT * FROM srv_user_grupa WHERE usr_id='".$usr_id."'");
+ // srv_user_grupa_archive1
+ $sqlD = sisplet_query("SELECT * FROM srv_user_grupa_archive1 WHERE usr_id='".$usr_id."'");
+ $pre_set = array( 'usr_id' => $new_usr_id,
+ 'time_edit' => "NOW()");
+ self::preformCopyTable('srv_user_grupa_archive1', null, self::sql2array($sqlD), $pre_set);
+
+ // srv_user_grupa_archive2
+ $sqlD = sisplet_query("SELECT * FROM srv_user_grupa_archive2 WHERE usr_id='".$usr_id."'");
+ $pre_set = array( 'usr_id' => $new_usr_id,
+ 'time_edit' => "NOW()");
+ self::preformCopyTable('srv_user_grupa_archive2', null, self::sql2array($sqlD), $pre_set);
+
+ // srv_user_grupa_archive3
+ $sqlD = sisplet_query("SELECT * FROM srv_user_grupa_archive3 WHERE usr_id='".$usr_id."'");
$pre_set = array( 'usr_id' => $new_usr_id,
'time_edit' => "NOW()");
- self::preformCopyTable('srv_user_grupa', null, self::sql2array($sqlD), $pre_set);
+ self::preformCopyTable('srv_user_grupa_archive3', null, self::sql2array($sqlD), $pre_set);
// srv_user_grupa_active
$sqlD = sisplet_query("SELECT * FROM srv_user_grupa_active WHERE usr_id='".$usr_id."'");
@@ -1338,10 +1528,12 @@ class SurveyCopy {
$array = array();
- while ($row = mysqli_fetch_assoc($sql)) {
-
- $array[] = $row;
-
+ if($sql){
+ while ($row = mysqli_fetch_assoc($sql)) {
+
+ $array[] = $row;
+
+ }
}
return $array;
@@ -1367,6 +1559,13 @@ class SurveyCopy {
return $arr;
}
+
+
+ public static function reset(){
+
+ self::$errors = null;
+ self::$source_array = null;
+ }
}