summaryrefslogtreecommitdiffstats
path: root/utils/SurveySyncDump.php
blob: 7f317f5df30185c4e1c365839fe84e25bc306b2c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

include_once ('../function.php');
include_once ('../admin/survey/definition.php');
include_once ('../vendor/autoload.php');

// daj to v settings.php za tablice :-)

global $connect_db;
$data = true;

$ftp_server= $terminal_ftp_server;
$ftp_user_name = $terminal_ftp_user_name;
$ftp_user_pass = $terminal_ftp_user_pass;

$dostop = new Dostop();
?>
<html>
    <head>
        <title>Sinhronizacija podatkov</title>
    <meta charset="utf-8">
</head>
<body>
<?
echo 'Pripravljam se na sinhronizacijo podatkov...<br>';

foreach ($terminal_surveys as $anketa) {
    
    echo 'Preverjam dostop do ankete ' .$anketa .'...';
    SurveyInfo::getInstance()->SurveyInit($anketa);
    
    if ($dostop->checkDostop($anketa) == true) {
        
        echo 'OK<br>';
    
        SurveyCopy::setSrcSurvey($anketa);
        SurveyCopy::setSrcConectDb($connect_db);
        SurveyCopy::setDestSite(0);
        $dump = SurveyCopy::downloadArrayVar($data);


        $nd = array();
        foreach ($dump as $kljuc=>$vrednost) {
            $nd[$terminal_id ."||~||" .$terminal_secret][$kljuc] = $vrednost;
        }

        
        $fn = $terminal_id ."-" .$anketa .'-'.date("YmdHis").'.1ka';
        $fp = fopen($site_path .'admin/survey/SurveyBackup/' .$fn, 'w');
        fwrite($fp, serialize($nd));
        fclose($fp);
        
        echo 'Anketa je izvožena, pripravljam prenos na strežnik....';

        $file = $fn;
        $remote_file = $fn;

        // set up basic connection
        $conn_id = ftp_connect($ftp_server);
        $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
        ftp_pasv($conn_id, true);

        // upload a file
        if (ftp_put($conn_id, $remote_file, $site_path .'admin/survey/SurveyBackup/' .$file, FTP_ASCII)) {
            echo 'OK. <br>Prenos ankete je uspel.<br><br>';

        } else {
            echo 'NAPAKA. <br>Prenos ankete ni uspel. ALI STE PRIKLOPLJENI NA INTERNET?<br><br>';
        }

        // close the connection
        ftp_close($conn_id);
    }
    
    else {
        echo 'nimate dostopa, zato ne izvažam!<br><strong>Ali ste prijavljeni?</strong><br>';
    }
}
?>

    <br><br>Opravljeno.