summaryrefslogtreecommitdiffstats
path: root/admin/survey/classes/class.SurveyExport.php
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--admin/survey/classes/class.SurveyExport.php387
1 files changed, 308 insertions, 79 deletions
diff --git a/admin/survey/classes/class.SurveyExport.php b/admin/survey/classes/class.SurveyExport.php
index 89133dc..893c1c3 100644
--- a/admin/survey/classes/class.SurveyExport.php
+++ b/admin/survey/classes/class.SurveyExport.php
@@ -11,12 +11,16 @@
*
*/
+use PhpOffice\PhpSpreadsheet\Spreadsheet;
+use PhpOffice\PhpSpreadsheet\IOFactory;
+use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
+
DEFINE (NEW_LINE, "\n");
DEFINE (TMP_EXT, '.tmp');
DEFINE (STR_DLMT, '|');
DEFINE (DAT_EXT, '.dat');
-define("EXPORT_FOLDER", "admin/survey/SurveyData");
+if (!defined('EXPORT_FOLDER')) define("EXPORT_FOLDER", "admin/survey/SurveyData");
class SurveyExport
{
@@ -47,7 +51,7 @@ class SurveyExport
private $_EXPORT_EXCEL_HEAD = true; # ali izvažamo header za excel
private $_EXPORT_EXCEL_REPLACE = array(); # ali izvažamo zamenjave za excel
- private $_SPECIAL_EXPORT = false; # samo za posebne primere kadar "moramo" izpisovati skrite sistemske variable (preko get se pošlje special_export=true
+ //private $_SPECIAL_EXPORT = false; # samo za posebne primere kadar "moramo" izpisovati skrite sistemske variable (preko get se pošlje special_export=true
private $_HEADERS = array(); # array z header podatki
@@ -87,8 +91,7 @@ class SurveyExport
$this->survey = SurveyInfo::getInstance()->getSurveyRow();
# aktivne tabele
- if (SurveyInfo::getInstance()->getSurveyColumn('db_table') == 1)
- $this->db_table = '_active';
+ $this->db_table = SurveyInfo::getInstance()->getSurveyArchiveDBString();
// Preverimo ce ima user dostop
$d = new Dostop();
@@ -112,14 +115,6 @@ class SurveyExport
# za profil časov
SurveyTimeProfiles :: Init($this->sid, $global_user_id);
-
- $result = sisplet_query ("SELECT value FROM misc WHERE what='SurveyExport'");
- list ($SurveyExport) = mysqli_fetch_row ($result);
- $adminTypes = array(0=>$lang['forum_admin'],1=>$lang['forum_manager'],2=>$lang['forum_clan'],3=>$lang['forum_registered'] );
-
- if ($SurveyExport<$admin_type) {
- die ($lang['srv_export_no_access'].$adminTypes[$admin_type]);
- }
# manjkajoče vrednosti
$this->SMV = new SurveyMissingValues($this->sid);
@@ -145,14 +140,14 @@ class SurveyExport
self::exportSpss();
break;
case 'excel':
- self::exportExcel();
+ self::exportCSV();
break;
case 'excel_xls':
self::exportExcelXls();
break;
- case 'txt':
+ /* case 'txt':
self::exportText();
- break;
+ break; */
}
}
@@ -160,30 +155,47 @@ class SurveyExport
*
*/
private function setUpFilter() {
+ global $global_user_id;
if ($this->_fileStatus >= 0) {
+ $filter_testdata = null;
+
$this->_HEADERS = unserialize(file_get_contents($this->_headFileName));
-
+
$this->exportSettings = array();
- foreach ($_SESSION AS $pkey => $pvalue)
+ //mislim, da se to ne porablja vec - smo sli iz seje v nastavitev na anketo
+ foreach ($_SESSION AS $pkey => $pvalue)
{
// if starts with export
if (!strncmp($pkey, "export", strlen("export")))
{
#ali iz seje ali preko requesta
$this->exportSettings[ltrim($pkey, "{export}")] = $pvalue
- || $_REQUEST[lcfirst($pvalue)];
+ || (isset($_REQUEST[lcfirst($pvalue)]) ? $_REQUEST[lcfirst($pvalue)] : null);
}
}
+
+ //pridobi nastavitve za export ankete
+ //kateri podatki so v export se sedaj veze na naketo (0-onlydata, 1-data in paradata, 2-identifikatorji)
+ $sql_export_mode = sisplet_query("SELECT value FROM srv_user_setting_for_survey
+ WHERE sid = '" . $this->sid . "' AND what='default_export_data_mode' AND uid='$global_user_id'");
+ $export_mode = 0;
+ if($sql_export_mode){
+ $export_mode = mysqli_fetch_assoc($sql_export_mode);
+ $export_mode = isset($export_mode['value']) ? $export_mode['value'] : 0;
+ }
+
+ $this->exportSettings['export_data'] = $export_mode;
- $this->_EXPORT_HIDDEN_SYSTEM = ($this->exportSettings['HiddenSystem']) ? true : false;
- $this->_EXPORT_HIDDEN_SYSTEM = ((int)$_REQUEST['hiddenSystem'] == 1 || $_REQUEST['hiddenSystem'] == 'true') ? true : $this->_EXPORT_HIDDEN_SYSTEM;
+ $this->_EXPORT_HIDDEN_SYSTEM = ($this->exportSettings['export_data'] == 2);
+ //$this->_EXPORT_HIDDEN_SYSTEM = (isset($_REQUEST['hiddenSystem']) && ((int)$_REQUEST['hiddenSystem'] == 1 || $_REQUEST['hiddenSystem'] == 'true')) ? true : $this->_EXPORT_HIDDEN_SYSTEM;
- $this->_EXPORT_FULL_META = ($this->exportSettings['FullMeta'] || !$this->_EXPORT_HIDDEN_SYSTEM) ? true : false;
- $this->_EXPORT_ONLY_DATA = ($this->exportSettings['OnlyData'] || !$this->_EXPORT_HIDDEN_SYSTEM) ? true : false;
+ $this->_EXPORT_FULL_META = (($this->exportSettings['export_data'] == 1)/* && !$this->_EXPORT_HIDDEN_SYSTEM */);
+ $this->_EXPORT_ONLY_DATA = (($this->exportSettings['export_data'] == 0)/* && !$this->_EXPORT_HIDDEN_SYSTEM */);
- $this->_SPECIAL_EXPORT = ($_REQUEST['special_export'] == 'true') ? true : false;
+ //nikjer v kodi nisem nasel 'special_export'
+ //$this->_SPECIAL_EXPORT = (isset($_REQUEST['special_export']) && $_REQUEST['special_export'] == 'true') ? true : false;
# filtriranje po statusih
$this->_CURRENT_STATUS_FILTER = SurveyStatusProfiles :: getStatusAsAWKString();
@@ -197,6 +209,8 @@ class SurveyExport
# filtriranje po časih
$_time_profile_awk = SurveyTimeProfiles :: getFilterForAWK($this->_HEADERS['unx_ins_date']['grids']['0']['variables']['0']['sequence']);
+ $filter_usability = null;
+
# ali imamo filter na uporabnost
if (isset($this->_HEADERS['usability']['variables'][0]['sequence']) && (int)$this->_HEADERS['usability']['variables'][0]['sequence'] > 0) {
$usability_data_sequence = $this->_HEADERS['usability']['variables'][0]['sequence'];
@@ -233,8 +247,8 @@ class SurveyExport
# ne prikazujemo user-idja
$not_svp_pv['uid'] = 'uid';
- # ne prikazujemo recnumberja
- //$not_svp_pv['recnum'] = 'recnum';
+ # ne prikazujemo casa klik na nagovor
+ $not_svp_pv['unx_ins_date'] = 'unx_ins_date';
# ne prikazujemo meta podatkov
if ($this->_EXPORT_FULL_META == false) {
@@ -253,16 +267,16 @@ class SurveyExport
foreach ($this->_HEADERS AS $spid => $spremenljivka) {
# privzeto spremenljivke ne prikazujemo
$_can_show = false;
- $tip = $spremenljivka['tip'];
+ $tip = isset($spremenljivka['tip']) ? $spremenljivka['tip'] : null;
# če spremenljivka ni v neprikazanih jo prikažemo
if (!in_array($spid, $not_svp_pv)) {
# če imamo sistemski email ali telefon, ime, priimek (v header je nastavljno "hide_system" = 1)
# potem v odvisnosti od nastavitve prikazujemo samo navadne podatke ali pa samo te sistemske, zaradizaščite podatkov
- if ($this->_EXPORT_HIDDEN_SYSTEM == true && $spremenljivka['hide_system'] == '1' || $this->_SPECIAL_EXPORT == true) {
+ if ($this->_EXPORT_HIDDEN_SYSTEM == true && isset($spremenljivka['hide_system']) && $spremenljivka['hide_system'] == '1' /* || $this->_SPECIAL_EXPORT == true */) {
# prikazujemo sistemske, in spremenljivka je sistemska
$_can_show = true;
} else
- if ( $this->_EXPORT_HIDDEN_SYSTEM == false && $spremenljivka['hide_system'] !== '1' ) {
+ if ($this->_EXPORT_HIDDEN_SYSTEM == false && (!isset($spremenljivka['hide_system']) || $spremenljivka['hide_system'] !== '1' )) {
# prikazujemo nesistemske, in spremenljivka ni sistemska
$_can_show = true;
}
@@ -281,15 +295,13 @@ class SurveyExport
if (count ($grid['variables']) > 0) {
foreach ($grid['variables'] AS $vid => $variable ){
- if (($tip !== 'sm' && $tip !== 'm') || $this->exportSettings['FullMeta'] > 0) {
+ if (($tip !== 'sm' && $tip !== 'm') || ($this->exportSettings['export_data'] == 1)) {
$_tmp_filter[]= $variable['sequence'];
}
}
}
}
}
-
- $spr_cont++;
}
}
}
@@ -317,12 +329,218 @@ class SurveyExport
echo 'Error! Empty file name!';
}
}
+
+ // Print data into active sheet
+ public function printSheetData($sheet, $data, $top_left = 'A1')
+ {
+ // Sample data
+ $sheet->fromArray(
+ $data, // The data to set
+ NULL, // Array values with this value will not be set
+ $top_left // Top left coordinate of the worksheet range where
+ );
+ }
- /** naredimo izvoz za excel - xls
+ /** naredimo izvoz za excel - xls
*
*/
function exportExcelXls() {
- global $site_path;
+ global $site_path, $lang;
+
+ $folder = $site_path . EXPORT_FOLDER.'/';
+
+ if ($this->_fileStatus >= 0 && $this->_dataFileName !== null && $this->_dataFileName !== '' && $this->_headFileName !== null && $this->_headFileName !== '') {
+
+ //za labele
+ $var_labels = array();
+ $missing_values = array();
+ $missing_values['-1'] = $lang['srv_bottom_data_legend_note_li1a'];
+ $missing_values['-2'] = $lang['srv_bottom_data_legend_note_li2a'];
+ $missing_values['-3'] = $lang['srv_bottom_data_legend_note_li3a'];
+ $missing_values['-4'] = $lang['srv_bottom_data_legend_note_li4a'];
+ $missing_values['-5'] = $lang['srv_bottom_data_legend_note_li5a'];
+ $missing_values['-97'] = $lang['srv_other_97'];
+ $missing_values['-98'] = $lang['srv_other_98'];
+ $missing_values['-99'] = $lang['srv_other_99'];
+
+ $data_table = array();
+
+ $spreadsheet = new Spreadsheet();
+ // Zavihek strani
+ $sheet = $spreadsheet->getActiveSheet();
+ $sheet->setTitle($lang['srv_podatki']);
+
+ $writer = new Xlsx($spreadsheet);
+
+ //stevec stolpcev po headerju
+ $stevec_headerja = 0;
+ # naredimo header row
+ foreach ($this->_HEADERS AS $spid => $spremenljivka) {
+ if (isset($this->_SVP_PV[$spid])) {
+ foreach ($spremenljivka['grids'] AS $gid => $grid) {
+ foreach ($grid['variables'] AS $vid => $variable ){
+ if(($spremenljivka['tip'] !== 'sm' && $spremenljivka['tip'] !== 'm') || ($this->exportSettings['export_data'] == 1)){
+ $data_table[0][] = strip_tags($variable['variable']);
+ $data_table[1][] = strip_tags($variable['naslov']);
+ $data_table_labels[0][] = strip_tags($variable['variable']);
+ $data_table_labels[1][] = strip_tags($variable['naslov']);
+
+ //labele po stolpcih, da se jih kasneje zamenja
+ $var_labels[$stevec_headerja] = $missing_values;
+ //dodamo vrednosti custom missingov
+ if(isset($spremenljivka['missing_values']))
+ $var_labels[$stevec_headerja] = $spremenljivka['missing_values']+$var_labels[$stevec_headerja];
+
+ if( in_array($spremenljivka['tip'], array(1,6,3))){
+ //dodamo na mesto stolpca, kjer se bodo zamenjali podatki z labelami
+ $var_labels[$stevec_headerja] = $var_labels[$stevec_headerja]+$spremenljivka['options'];
+ }
+ elseif( in_array($spremenljivka['tip'], array(2,16))){
+ //dodamo na mesto stolpca, kjer se bodo zamenjali podatki z labelami
+ $var_labels[$stevec_headerja] = $var_labels[$stevec_headerja]+array("0"=>$lang['srv_checked_value_0'], "1"=>$lang['srv_checked_value_1']);
+ }
+
+ $stevec_headerja++;
+ }
+ }
+ }
+ }
+ }
+
+ # sfiltriramo podatke
+ exec ('awk -F'.$this->_QUOTE.STR_DLMT.$this->_QUOTE.' '.$this->_QUOTE.$this->_CURRENT_STATUS_FILTER.' {print $0}'.$this->_QUOTE.' '.$this->_dataFileName.' > '.$this->_dataFileName .'_data1'.TMP_EXT);
+ if (IS_WINDOWS) {
+ #filtri spremenljivk
+ $cmdLn1_1 = 'cut -d "|" -f '.$this->_VARIABLE_FILTER.' '.$this->_dataFileName .'_data1'.TMP_EXT.' > '.$this->_dataFileName .'_data1_1'.TMP_EXT;
+ } else {
+ #filtri spremenljivk
+ $cmdLn1_1 = 'cut -d \'|\' -f '.$this->_VARIABLE_FILTER.' '.$this->_dataFileName .'_data1'.TMP_EXT.' > '.$this->_dataFileName .'_data1_1'.TMP_EXT;
+ }
+ $out1_1 = shell_exec($cmdLn1_1);
+
+ //gremo cez podatke, zacnemo z vrstico 3 zaradi headerja
+ $line_num = 2;
+ $fileLines = file($this->_dataFileName .'_data1_1'.TMP_EXT, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
+ foreach ($fileLines as $line) {
+ $line_arr = explode('|', $line);
+ foreach ($line_arr as $index=>$cell) {
+ //labele
+ if(in_array($index, array_keys($var_labels))){
+ $data_table_labels[$line_num][] = isset($var_labels[$index][$cell]) ? $var_labels[$index][$cell] : $cell;
+ $data_table[$line_num][] = $cell;
+ }
+ //grobi podatki
+ else{
+ $data_table_labels[$line_num][] = $cell;
+ $data_table[$line_num][] = $cell;
+ }
+ }
+ $line_num ++;
+ }
+
+ //sprintamo vse podatke (skupaj s header) v tabelo
+ $this->printSheetData($sheet, $data_table);
+
+ // Style table header
+ $range_header = $this->getRange(0, 2, 0, count($data_table[0])-1);
+
+ $style_header = array(
+ /* 'font' => array(
+ 'bold' => true
+ ),
+ 'alignment' => array(
+ 'center' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER,
+ ),
+ 'borders' => array(
+ 'allBorders' => array('borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN),
+ ), */
+ 'fill' => array(
+ 'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
+ 'startColor' => [
+ 'argb' => 'FFF0F0F0',
+ ],
+ 'endColor' => [
+ 'argb' => 'FFF0F0F0',
+ ],
+ ),
+ );
+ //set style to header
+ $sheet->getStyle($range_header)->applyFromArray($style_header);
+ //freeze header
+ $sheet->freezePane('A3');
+
+ //SHEET Z LABELAMI
+ // Create a new sheet with
+ $secondSheet = new \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet($spreadsheet, $lang['srv_dataIcons_labels']);
+ // Add the new sheet to the spreadsheet
+ $spreadsheet->addSheet($secondSheet);
+ //sprintamo vse podatke (skupaj s header) v tabelo
+ $this->printSheetData($secondSheet, $data_table_labels);
+ //set style to header
+ $secondSheet->getStyle($range_header)->applyFromArray($style_header);
+ //freeze header
+ $secondSheet->freezePane('A3');
+
+ $spreadsheet->setActiveSheetIndex(0);
+
+ $file_name_full = $this->_dataFileName . '.xlsx';
+
+ //shranimo datoteko
+ $writer->save($file_name_full);
+
+ // Set headers for file download
+ header('Content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
+ header('Content-Disposition: attachment; filename="anketa' . $this->sid . '-' . date('Y-m-d') . '.xlsx"');
+ header('Pragma: public');
+ header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
+ header('Content-Transfer-Encoding: binary');
+ header('Expires: 0');
+ ob_clean();
+ flush();
+
+ // Output file contents for download
+ readfile($file_name_full);
+
+ #pobrišemo vse tmp datoteke
+ foreach (glob($folder . 'export_data_'.$this->sid.'_*'.TMP_EXT) as $fileToDelete) {
+ unlink($fileToDelete);
+ }
+ unlink ($file_name_full);
+
+ } else {
+ echo '';
+ }
+
+ exit;
+ }
+
+ // Get range
+ private function getRange($row_start, $row_end, $col_start, $col_end)
+ {
+ $start_col_name = $this->getExcelColumn($col_start);
+ $end_col_name = $this->getExcelColumn($col_end);
+
+ $range = $start_col_name . $row_start . ':' . $end_col_name . $row_end;
+ return $range;
+ }
+
+ //get excel name of column based on number of column
+ private function getExcelColumn($col_number) {
+ $base = ord('A');
+ $letters = '';
+
+ while ($col_number >= 0) {
+ $letters = chr($col_number % 26 + $base) . $letters;
+ $col_number = (int)($col_number / 26) - 1;
+ }
+
+ return $letters;
+ }
+
+ /** naredimo izvoz za excel - xls (stara verzija s html zapisom)
+ *
+ */
+ function exportExcelXlsOld() {
global $site_path;
$folder = $site_path . EXPORT_FOLDER.'/';
@@ -342,7 +560,7 @@ class SurveyExport
foreach ($spremenljivka['grids'] AS $gid => $grid) {
foreach ($grid['variables'] AS $vid => $variable ){
- if(($spremenljivka['tip'] !== 'sm' && $spremenljivka['tip'] !== 'm') || $this->exportSettings['FullMeta'] > 0){
+ if(($spremenljivka['tip'] !== 'sm' && $spremenljivka['tip'] !== 'm') || ($this->exportSettings['export_data'] == 1)){
$output1 .= '<td>'.strip_tags($variable['variable']).'</td>';
$output2 .= '<td>'.strip_tags($variable['naslov']).'</td>';
}
@@ -434,35 +652,36 @@ class SurveyExport
exit;
}
- /** naredimo izvoz za excel
+ /** naredimo izvoz za csv
*
*/
- function exportExcel() {
+ function exportCSV() {
global $site_path;
$folder = $site_path . EXPORT_FOLDER.'/';
session_start();
if ($this->_fileStatus >= 0 && $this->_dataFileName !== null && $this->_headFileName !== null) {
+ $file_csv = ((int)$_POST['export_format'] == 1);
+ $extension = ($file_csv) ? '.csv' : '.txt';
+
if ($_POST['export_delimit'] == 0) {
$field_delimit = ';';
- $replace_what = $_POST['replace_what0'];
- $replace_with = $_POST['replace_with0'];
+ $replace_what = isset($_POST['replace_what0']) ? $_POST['replace_what0'] : array();
+ $replace_with = isset($_POST['replace_with0']) ? $_POST['replace_with0'] : array();
} else {
$field_delimit = ',';
- $replace_what = $_POST['replace_what1'];
- $replace_with = $_POST['replace_with1'];
+ $replace_what = isset($_POST['replace_what1']) ? $_POST['replace_what1'] : array();
+ $replace_with = isset($_POST['replace_with1']) ? $_POST['replace_with1'] : array();
}
#zapišemo v temp file
- $file_handler = fopen($this->_dataFileName.'.csv',"w");
+ $file_handler = fopen($this->_dataFileName.$extension,"w");
$output1 = '';
$output2 = '';
-
fclose($file_handler);
-
# sfiltriramo podatke
exec ('awk -F'.$this->_QUOTE.STR_DLMT.$this->_QUOTE.' '.$this->_QUOTE.$this->_CURRENT_STATUS_FILTER.' {print $0}'.$this->_QUOTE.' '.$this->_dataFileName.' > '.$this->_dataFileName .'_data1'.TMP_EXT);
@@ -484,13 +703,16 @@ class SurveyExport
exec('sed '.$this->_QUOTE .'s/'.$replace_what[$i].'/'.$replace_with[$i].'/g'.$this->_QUOTE .' '.$this->_dataFileName .'_data1_'.($i+1).TMP_EXT.' > '.$this->_dataFileName .'_data1_'.($i+2).TMP_EXT);
$_new_filename = '_data1_'.($i+2);
}
-
+
} else {
$_new_filename = '_data1_1';
}
# zamenjamo | z ;
- exec('sed '.$this->_QUOTE.'s/|/\x22'.$field_delimit.'=\x22/g'.$this->_QUOTE.' '.$this->_dataFileName .$_new_filename.TMP_EXT.' >> '.$this->_dataFileName.'.csv');
+ if($file_csv)
+ exec('sed '.$this->_QUOTE.'s/|/\x22'.$field_delimit.'=\x22/g'.$this->_QUOTE.' '.$this->_dataFileName .$_new_filename.TMP_EXT.' >> '.$this->_dataFileName.$extension);
+ else
+ exec('sed '.$this->_QUOTE.'s/|/'.$field_delimit.'/g'.$this->_QUOTE.' '.$this->_dataFileName .'_data1_1'.TMP_EXT.' >> '.$this->_dataFileName.$extension);
$convertType = 1; // kateri tip konvertiranja uporabimo
$convertTypes[1] = array('charSet' => 'windows-1250',
@@ -500,14 +722,14 @@ class SurveyExport
# izvedemo download
- if ($fd = fopen ($this->_dataFileName.'.csv', "r")) {
- $fsize = filesize($this->_dataFileName.'.csv');
- $path_parts = pathinfo($this->_dataFileName.'.csv');
+ if ($fd = fopen ($this->_dataFileName.$extension, "r")) {
+ $fsize = filesize($this->_dataFileName.$extension);
+ $path_parts = pathinfo($this->_dataFileName.$extension);
$ext = strtolower($path_parts["extension"]);
#ob_clean();
#header('Content-type: application/vnd.ms-excel; charset='.$convertTypes[$convertType]['charSet']);
header('Content-type: text/csv; charset='.$convertTypes[$convertType]['charSet']);
- header('Content-Disposition: attachment; filename="anketa'.$this->sid.'-'.date('Y-m-d').'.csv"');
+ header('Content-Disposition: attachment; filename="anketa'.$this->sid.'-'.date('Y-m-d').$extension.'"');
# ker iz zacasne datoteke preberemo samo podatke brez headerja (header izpisujemo posebej)
# ne moremo podati content-lenght. Razen če bi predhodno vsae zapisali v tmp datoteko in potem prebrali dolžino
# header('Content-length: '.$fsize);
@@ -521,14 +743,14 @@ class SurveyExport
echo $convertTypes[$convertType]['BOMchar'];
# naredimo header row
- if ((int)$_POST['export_labels'] == 1) {
+ if ((int)$_POST['export_headers'] == 1) {
foreach ($this->_HEADERS AS $spid => $spremenljivka) {
if (isset($this->_SVP_PV[$spid])) {
if (count($spremenljivka['grids']) > 0) {
foreach ($spremenljivka['grids'] AS $gid => $grid) {
foreach ($grid['variables'] AS $vid => $variable ){
- if(($spremenljivka['tip'] !== 'sm' && $spremenljivka['tip'] !== 'm') || $this->exportSettings['FullMeta'] > 0){
+ if(($spremenljivka['tip'] !== 'sm' && ($spremenljivka['tip'] !== 'm') || $this->exportSettings['export_data'] == 1)){
$output1 .= str_replace($replace_what, $replace_with, strip_tags($variable['variable'])) . $field_delimit;
$output2 .= str_replace($replace_what, $replace_with, strip_tags($variable['naslov'])) . $field_delimit;
}
@@ -542,10 +764,10 @@ class SurveyExport
}
while ($line= fgets ($fd)) {
- echo '="';
+ if($file_csv) echo '="';
$line = str_replace(array("\r","\n"), array("",""), $line);
print ($line);
- print ('"');
+ if($file_csv) print ('"');
print ("\r\n");
}
}
@@ -558,7 +780,7 @@ class SurveyExport
foreach (glob($folder . 'export_data_'.$this->sid.'*dat_data*'.TMP_EXT) as $fileToDelete) {
unlink($fileToDelete);
}
- unlink ($this->_dataFileName.'.csv');
+ unlink ($this->_dataFileName.$extension);
}
else {
echo 'x2:Napaka!';
@@ -567,16 +789,26 @@ class SurveyExport
exit;
}
- /** naredimo izvoz za txt
+ /** naredimo izvoz za txt SEDAJ JE TO VKLJUCENO V CSV
*
*/
- function exportText() {
+ /* function exportText() {
global $site_path;
$folder = $site_path . EXPORT_FOLDER.'/';
if ($this->_fileStatus >= 0 && $this->_dataFileName !== null && $this->_dataFileName !== '' && $this->_headFileName !== null && $this->_headFileName !== '') {
+ if ($_POST['export_delimit'] == 0) {
+ $field_delimit = ';';
+ $replace_what = isset($_POST['replace_what0']) ? $_POST['replace_what0'] : array();
+ $replace_with = isset($_POST['replace_with0']) ? $_POST['replace_with0'] : array();
+ } else {
+ $field_delimit = ',';
+ $replace_what = isset($_POST['replace_what1']) ? $_POST['replace_what1'] : array();
+ $replace_with = isset($_POST['replace_with1']) ? $_POST['replace_with1'] : array();
+ }
+
#zapišemo v temp file
$file_handler = fopen($this->_dataFileName.'.txt',"w");
@@ -585,7 +817,7 @@ class SurveyExport
$output2 = '';
// array za labele (ce jih izpisujemo)
- $display_labels = true;
+ $display_labels = ((int)$_POST['export_labels'] == 1);
$labels = array();
# naredimo header row
@@ -594,7 +826,7 @@ class SurveyExport
foreach ($spremenljivka['grids'] AS $gid => $grid) {
foreach ($grid['variables'] AS $vid => $variable ){
- if(($spremenljivka['tip'] !== 'sm' && $spremenljivka['tip'] !== 'm') || $this->exportSettings['FullMeta'] > 0){
+ if(($spremenljivka['tip'] !== 'sm' && $spremenljivka['tip'] !== 'm') || (isset($this->exportSettings['FullMeta']) && $this->exportSettings['FullMeta'] > 0)){
$output1 .= strip_tags($variable['variable']).';';
$output2 .= strip_tags($variable['naslov']).';';
}
@@ -663,10 +895,10 @@ class SurveyExport
# dodami boomchar za utf-8
echo $convertTypes[$convertType]['BOMchar'];
- /*while(!feof($fd)) {
- $buffer = fread($fd, 2048);
- echo $buffer.'';
- }*/
+ //while(!feof($fd)) {
+ // $buffer = fread($fd, 2048);
+ // echo $buffer.'';
+ //}
$i=0;
// Loop po vrsticah
while(($line = fgets($fd)) !== false) {
@@ -718,7 +950,7 @@ class SurveyExport
}
exit;
- }
+ } */
// shranim SPS in A00, potem pokličem spss in je.
private function exportSav () {
@@ -753,7 +985,7 @@ class SurveyExport
header("Content-Transfer-Encoding: Binary");
header("Content-disposition: attachment; filename=\"" . basename($file_url) . "\"");
- readfile($file_url);
+ /* if(file_exists($file_url)) */readfile($file_url);
}
@@ -820,7 +1052,7 @@ class SurveyExport
$_max_text_missing_chars = max($_max_text_missing_chars, strlen($mkey . ': '. $missing));
$_max_number_missing_chars = max($_max_number_missing_chars, strlen($mkey));
}
- $maxLengthForSpr = self::create_array_SPSS(max($_max_text_missing_chars,$_max_number_missing_chars));
+ $maxLengthForSpr = $this->create_array_SPSS(max($_max_text_missing_chars,$_max_number_missing_chars));
//$resultString .= .NEW_LINE;
$resultString = $lang['srv_spss_export_base_instructions'];
$resultString .= NEW_LINE.'.'.NEW_LINE.NEW_LINE;
@@ -870,7 +1102,7 @@ class SurveyExport
foreach ($grid['variables'] AS $vid => $variable ){
$seq=$variable['sequence'];
- if(($spremenljivka['tip'] !== 'sm' && $spremenljivka['tip'] !== 'm') || $this->exportSettings['FullMeta'] > 0){
+ if(!isset($spremenljivka['tip']) || ($spremenljivka['tip'] !== 'sm' && $spremenljivka['tip'] !== 'm') || $this->exportSettings['export_data'] == 1){
# vsako v svojo vrstico
if (substr($variable['spss'],0,1) == 'F') {
@@ -951,7 +1183,7 @@ class SurveyExport
if (count($grid['variables']) > 0) {
foreach ($grid['variables'] AS $vid => $variable ){
- if(($spremenljivka['tip'] !== 'sm' && $spremenljivka['tip'] !== 'm') || $this->exportSettings['FullMeta'] > 0){
+ if(!isset($spremenljivka['tip']) || ($spremenljivka['tip'] !== 'sm' && $spremenljivka['tip'] !== 'm') || $this->exportSettings['export_data'] == 1){
switch ($spremenljivka['tip']) {
case '2':
@@ -1016,7 +1248,7 @@ class SurveyExport
if (count($grid['variables']) > 0) {
foreach ($grid['variables'] AS $vid => $variable ){
- if(($spremenljivka['tip'] !== 'sm' && $spremenljivka['tip'] !== 'm') || $this->exportSettings['FullMeta'] > 0){
+ if(($spremenljivka['tip'] !== 'sm' && $spremenljivka['tip'] !== 'm') || $this->exportSettings['export_data'] == 1){
if ($variable['other'] != 1) {
$variable = $this->getCleanString($variable['variable']);
@@ -1034,7 +1266,7 @@ class SurveyExport
if (count($spremenljivka['options']) > 0) {
foreach ($spremenljivka['options'] AS $okey =>$option) {
- if(($spremenljivka['tip'] !== 'sm' && $spremenljivka['tip'] !== 'm') || $this->exportSettings['FullMeta'] > 0){
+ if(($spremenljivka['tip'] !== 'sm' && $spremenljivka['tip'] !== 'm') || $this->exportSettings['export_data'] == 1){
if ($spremenljivka['tip'] == 2 || $spremenljivka['tip'] == 16) {
# pri čekboxu prevedemo
@@ -1121,7 +1353,7 @@ class SurveyExport
if ($pspp == false)
$resultString .= $mkey . ' \'' . $this->getCleanString($missing_value).'\''.NEW_LINE;
else {
- if (strpos ($this->getCleanString($unset_value), "&#39;")===false) {
+ if (strpos ($this->getCleanString($missing_value), "&#39;")===false) {
$resultString .= $mkey . ' "' . $this->getCleanString($missing_value).'"'.' ';
}
else {
@@ -1266,7 +1498,7 @@ class SurveyExport
$out3 = shell_exec($cmdLn3);
$out4 = shell_exec($cmdLn4);
- if ($_GET['debug'] == 1) {
+ if (isset($_GET['debug']) && $_GET['debug'] == 1) {
print_r('<br>'.$cmdLn1);
print_r('<br>'.$cmdLn2);
print_r('<br>'.$cmdLn3);
@@ -1361,19 +1593,16 @@ class SurveyExport
private function create_array_SPSS($max_missing) {
$array_SPSS = array();
- $db_table = ($this->survey['db_table'] == 1) ? '_active' : '';
-
# poberemo max dolžine iz srv_data_text max(text1,text2)
- $str_query = 'SELECT dt.spr_id, MAX(LENGTH(dt.text)) AS length, MAX(LENGTH(dt.text2)) AS length2 FROM srv_data_text'.$db_table.' dt, srv_grupa g, srv_spremenljivka s WHERE dt.spr_id = s.id AND s.gru_id=g.id AND g.ank_id='.$this->sid.' GROUP BY dt.spr_id';
+ $str_query = 'SELECT dt.spr_id, MAX(LENGTH(dt.text)) AS length, MAX(LENGTH(dt.text2)) AS length2 FROM srv_data_text'.$this->db_table.' dt, srv_grupa g, srv_spremenljivka s WHERE dt.spr_id = s.id AND s.gru_id=g.id AND g.ank_id='.$this->sid.' GROUP BY dt.spr_id';
$_qry_SPSS = sisplet_query($str_query);
while (list($spr_id,$text,$text2) = mysqli_fetch_row($_qry_SPSS)) {
$array_SPSS[$spr_id] = max((int)$text,(int)$text2,$max_missing);
}
- $str_query = 'SELECT dt.spr_id, MAX(LENGTH(dt.text)) AS length FROM srv_data_textgrid'.$db_table.' AS dt, srv_grupa g, srv_spremenljivka s WHERE dt.spr_id = s.id AND s.gru_id=g.id AND g.ank_id='.$this->sid.' GROUP BY dt.spr_id';
+ $str_query = 'SELECT dt.spr_id, MAX(LENGTH(dt.text)) AS length FROM srv_data_textgrid'.$this->db_table.' AS dt, srv_grupa g, srv_spremenljivka s WHERE dt.spr_id = s.id AND s.gru_id=g.id AND g.ank_id='.$this->sid.' GROUP BY dt.spr_id';
$_qry_SPSS = sisplet_query($str_query);
while (list($spr_id,$text) = mysqli_fetch_row($_qry_SPSS)) {
- #$this->_array_SPSS[$spr_id]['text2'] = ((int)$text < $this->MISSING_MAX_LENGTH ? $this->MISSING_MAX_LENGTH :$text);
- $array_SPSS[$spr_id] = max((int)$text,$array_SPSS[$spr_id],$max_missing);
+ $array_SPSS[$spr_id] = isset($array_SPSS[$spr_id]) ? max((int)$text,$array_SPSS[$spr_id],$max_missing) : max((int)$text,0,$max_missing);
}
return $array_SPSS;
}
@@ -1408,7 +1637,7 @@ class SurveyExport
return $new_string;
}
- private function getVariableLabels($spr_id){
+ /* private function getVariableLabels($spr_id){
global $lang;
$s = sisplet_query("SELECT tip FROM srv_spremenljivka WHERE id = '$spr_id'");
@@ -1460,6 +1689,6 @@ class SurveyExport
}
return $response;
- }
+ } */
}
?> \ No newline at end of file