2012-10-17 16:23:22 -04:00
|
|
|
<?php
|
2018-02-07 16:39:30 -04:00
|
|
|
|
2012-10-17 16:23:22 -04:00
|
|
|
require_once "classes/model/Language.php";
|
|
|
|
|
|
2018-08-28 09:34:11 -04:00
|
|
|
use ProcessMaker\Validation\ValidationUploadedFiles;
|
|
|
|
|
|
2012-10-17 16:23:22 -04:00
|
|
|
global $RBAC;
|
2018-02-07 16:39:30 -04:00
|
|
|
$access = $RBAC->userCanAccess('PM_SETUP_ADVANCE');
|
2012-10-17 16:23:22 -04:00
|
|
|
|
|
|
|
|
if ($access != 1) {
|
|
|
|
|
switch ($access) {
|
|
|
|
|
case - 1:
|
2018-02-07 16:39:30 -04:00
|
|
|
G::SendTemporalMessage('ID_USER_HAVENT_RIGHTS_PAGE', 'error', 'labels');
|
2012-10-17 16:23:22 -04:00
|
|
|
break;
|
|
|
|
|
case - 2:
|
2018-02-07 16:39:30 -04:00
|
|
|
G::SendTemporalMessage('ID_USER_HAVENT_RIGHTS_SYSTEM', 'error', 'labels');
|
2012-10-17 16:23:22 -04:00
|
|
|
break;
|
|
|
|
|
default:
|
2018-02-07 16:39:30 -04:00
|
|
|
G::SendTemporalMessage('ID_USER_HAVENT_RIGHTS_PAGE', 'error', 'labels');
|
2012-10-17 16:23:22 -04:00
|
|
|
break;
|
|
|
|
|
}
|
2018-02-07 16:39:30 -04:00
|
|
|
G::header('location: ../login/login');
|
|
|
|
|
exit(0);
|
2012-10-17 16:23:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$result = new stdClass();
|
|
|
|
|
|
|
|
|
|
try {
|
2018-12-13 14:42:05 -04:00
|
|
|
ValidationUploadedFiles::getValidationUploadedFiles()->dispatch(function($validator) {
|
2018-08-28 09:34:11 -04:00
|
|
|
throw new Exception($validator->getMessage());
|
|
|
|
|
});
|
2012-10-17 16:23:22 -04:00
|
|
|
//if the xmlform path is writeable
|
2018-02-07 16:39:30 -04:00
|
|
|
if (!is_writable(PATH_XMLFORM)) {
|
|
|
|
|
throw new Exception(G::LoadTranslation('IMPORT_LANGUAGE_ERR_NO_WRITABLE'));
|
|
|
|
|
}
|
2012-10-17 16:23:22 -04:00
|
|
|
|
2018-02-07 16:39:30 -04:00
|
|
|
//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'));
|
|
|
|
|
}
|
2012-10-17 16:23:22 -04:00
|
|
|
|
2018-02-07 16:39:30 -04:00
|
|
|
$sMaxExecutionTime = ini_get('max_execution_time');
|
|
|
|
|
ini_set('max_execution_time', '0');
|
2017-02-14 21:24:08 +00:00
|
|
|
|
2015-03-26 16:31:46 -04:00
|
|
|
$filter = new InputFilter();
|
2012-10-17 16:23:22 -04:00
|
|
|
|
|
|
|
|
$languageFile = $_FILES['form']['tmp_name']['LANGUAGE_FILENAME'];
|
|
|
|
|
$languageFilename = $_FILES['form']['name']['LANGUAGE_FILENAME'];
|
2015-04-06 17:43:51 -04:00
|
|
|
$languageFile = $filter->xssFilterHard($languageFile, 'path');
|
2015-03-26 16:31:46 -04:00
|
|
|
$languageFilename = $filter->xssFilterHard($languageFilename, 'path');
|
2018-02-07 16:39:30 -04:00
|
|
|
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);
|
2012-10-17 16:23:22 -04:00
|
|
|
}
|
2018-02-07 16:39:30 -04:00
|
|
|
gzclose($zp);
|
|
|
|
|
fclose($handle);
|
2012-10-17 16:23:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$language = new Language();
|
2018-02-07 16:39:30 -04:00
|
|
|
$importResults = $language->import($languageFile);
|
2012-10-17 16:23:22 -04:00
|
|
|
|
2018-02-07 16:39:30 -04:00
|
|
|
$result->success = true;
|
|
|
|
|
$result->msg = G::LoadTranslation('IMPORT_LANGUAGE_SUCCESS') . "\n";
|
2013-07-17 12:05:37 -04:00
|
|
|
$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";
|
2012-10-17 16:23:22 -04:00
|
|
|
|
|
|
|
|
if ($importResults->errMsg != '') {
|
2018-02-07 16:39:30 -04:00
|
|
|
$result->msg .= G::LoadTranslation("ID_ERROR_REGISTERED") . " \n" . $importResults->errMsg . "\n";
|
2012-10-17 16:23:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//saving metadata
|
2018-02-07 16:39:30 -04:00
|
|
|
$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();
|
2012-10-17 16:23:22 -04:00
|
|
|
|
2013-04-17 14:45:58 -04:00
|
|
|
$dir = PATH_CORE . 'content' . PATH_SEP . 'translations' . PATH_SEP;
|
2018-02-07 16:39:30 -04:00
|
|
|
if (!is_writable($dir)) {
|
|
|
|
|
throw new Exception(G::LoadTranslation('ID_TRANSLATIONS_FOLDER_PERMISSIONS'));
|
2013-04-17 14:45:58 -04:00
|
|
|
}
|
|
|
|
|
G::uploadFile($languageFile, $dir, $languageFilename, 0777);
|
|
|
|
|
|
2018-02-07 16:39:30 -04:00
|
|
|
ini_set('max_execution_time', $sMaxExecutionTime);
|
2012-10-17 16:23:22 -04:00
|
|
|
} catch (Exception $oError) {
|
|
|
|
|
$result->success = false;
|
2018-02-07 16:39:30 -04:00
|
|
|
$result->msg = $oError->getMessage();
|
2012-10-17 16:23:22 -04:00
|
|
|
}
|
2018-02-07 16:39:30 -04:00
|
|
|
|
|
|
|
|
ob_clean();
|
|
|
|
|
echo G::json_encode($result);
|
2012-10-17 16:23:22 -04:00
|
|
|
|