File size: 3,380 Bytes
07c3cdd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
88
89
90
91
92
93
94
<?php

require_once "classes/model/Language.php";

global $RBAC;
$access = $RBAC->userCanAccess('PM_SETUP_ADVANCE');

if ($access != 1) {
    switch ($access) {
        case - 1:
            G::SendTemporalMessage('ID_USER_HAVENT_RIGHTS_PAGE', 'error', 'labels');
            break;
        case - 2:
            G::SendTemporalMessage('ID_USER_HAVENT_RIGHTS_SYSTEM', 'error', 'labels');
            break;
        default:
            G::SendTemporalMessage('ID_USER_HAVENT_RIGHTS_PAGE', 'error', 'labels');
            break;
    }
    G::header('location: ../login/login');
    exit(0);
}

$result = new stdClass();

try {
    //if the xmlform path is writeable
    if (!is_writable(PATH_XMLFORM)) {
        throw new Exception(G::LoadTranslation('IMPORT_LANGUAGE_ERR_NO_WRITABLE'));
    }

    //if all xml files within the xmlform directory are writeable
    if (!G::is_rwritable(PATH_XMLFORM)) {
        throw new Exception(G::LoadTranslation('IMPORT_LANGUAGE_ERR_NO_WRITABLE2'));
    }

    $sMaxExecutionTime = ini_get('max_execution_time');
    ini_set('max_execution_time', '0');

    $filter = new InputFilter();

    $languageFile = $_FILES['form']['tmp_name']['LANGUAGE_FILENAME'];
    $languageFilename = $_FILES['form']['name']['LANGUAGE_FILENAME'];
    $languageFile = $filter->xssFilterHard($languageFile, 'path');
    $languageFilename = $filter->xssFilterHard($languageFilename, 'path');
    if (substr_compare($languageFilename, ".gz", - 3, 3, true) == 0) {
        $zp = gzopen($languageFile, "r");
        $languageFile = tempnam(__FILE__, '');
        $handle = fopen($languageFile, "w");
        while (!gzeof($zp)) {
            $data = gzread($zp, 1024);
            fwrite($handle, $data);
        }
        gzclose($zp);
        fclose($handle);
    }

    $language = new Language();
    $importResults = $language->import($languageFile);

    $result->success = true;
    $result->msg = G::LoadTranslation('IMPORT_LANGUAGE_SUCCESS') . "\n";
    $result->msg .= G::LoadTranslation("ID_FILE_NUM_RECORD") . $importResults->recordsCount . "\n";
    $result->msg .= G::LoadTranslation("ID_SUCCESS_RECORD") . $importResults->recordsCountSuccess . "\n";
    $result->msg .= G::LoadTranslation("ID_FAILED_RECORD") . ($importResults->recordsCount - $importResults->recordsCountSuccess) . "\n";

    if ($importResults->errMsg != '') {
        $result->msg .= G::LoadTranslation("ID_ERROR_REGISTERED") . " \n" . $importResults->errMsg . "\n";
    }

    //saving metadata
    $configuration = new Configurations();
    $configuration->aConfig = Array('headers' => $importResults->headers, 'language' => $importResults->lang, 'import-date' => date('Y-m-d H:i:s'), 'user' => '', 'version' => '1.0');
    $configuration->saveConfig('LANGUAGE_META', $importResults->lang);

    $renegerateContent = new WorkspaceTools(config("system.workspace"));
    $messs = $renegerateContent->upgradeContent();

    $dir = PATH_CORE . 'content' . PATH_SEP . 'translations' . PATH_SEP;
    if (!is_writable($dir)) {
        throw new Exception(G::LoadTranslation('ID_TRANSLATIONS_FOLDER_PERMISSIONS'));
    }
    G::uploadFile($languageFile, $dir, $languageFilename, 0777);

    ini_set('max_execution_time', $sMaxExecutionTime);
} catch (Exception $oError) {
    $result->success = false;
    $result->msg = $oError->getMessage();
}

ob_clean();
echo G::json_encode($result);