Joywork/admin/loadBlockFiles.php

104 lines
4.8 KiB
PHP
Raw Permalink Normal View History

2026-05-22 20:21:54 +02:00
<?php
require_once($_SERVER['DOCUMENT_ROOT'] . "/config.php");
include $_SERVER['DOCUMENT_ROOT'] . '/import/obj/ImportRecord.php';
include $_SERVER['DOCUMENT_ROOT'] . '/import/document/target/DocTarget.php';
include $_SERVER['DOCUMENT_ROOT'] . '/import/obj/Block.php';
include $_SERVER['DOCUMENT_ROOT'] . '/import/obj/Apartment.php';
include $_SERVER['DOCUMENT_ROOT'] . '/import/document/target/BlockProgressImageFacade.php';
include $_SERVER['DOCUMENT_ROOT'] . '/import/document/target/BlockPlusFacade.php';
include $_SERVER['DOCUMENT_ROOT'] . '/import/document/target/TargetFactory.php';
include $_SERVER['DOCUMENT_ROOT'] . '/import/document/DocumentManager.php';
include $_SERVER['DOCUMENT_ROOT'] . '/import/document/provider/DocProvider.php';
include $_SERVER['DOCUMENT_ROOT'] . '/import/document/provider/DbDocProvider.php';
include $_SERVER['DOCUMENT_ROOT'] . '/import/document/entity/Dir.php';
include $_SERVER['DOCUMENT_ROOT'] . '/import/document/entity/RootDir.php';
include $_SERVER['DOCUMENT_ROOT'] . '/import/document/entity/File.php';
include $_SERVER['DOCUMENT_ROOT'] . '/import/document/entity/DocCollection.php';
include $_SERVER['DOCUMENT_ROOT'] . '/import/document/ar/Document.php';
include $_SERVER['DOCUMENT_ROOT'] . '/import/document/exception/DocNotFoundException.php';
include $_SERVER['DOCUMENT_ROOT'] . '/import/document/exception/TargetNotFoundException.php';
ini_set('display_errors', 1);
error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE);
$result = "";
$updateContent = false;
$markupId = "";
for ($i = 0; $i < count($_FILES['docFiles']['name']); $i++) {
if ($_FILES['docFiles']['error'][$i] == 0) {
$ext = strtolower(pathinfo($_FILES['docFiles']['name'][$i], PATHINFO_EXTENSION));
$name = substr(md5($_POST['fold_id'] . '_' . $_POST['target_type'] . '_' . $_POST['target_id']), 0, 5) . time() . $i . '.' . strtolower($ext);
if (!is_dir($_SERVER['DOCUMENT_ROOT'] . "/documents")) {
mkdir($_SERVER['DOCUMENT_ROOT'] . "/documents");
}
$one = mb_substr($name, 0, 1);
if (!is_dir($_SERVER['DOCUMENT_ROOT'] . "/documents/$one")) {
mkdir($_SERVER['DOCUMENT_ROOT'] . "/documents/$one");
}
$two = mb_substr($name, 1, 1);
if (!is_dir($_SERVER['DOCUMENT_ROOT'] . "/documents/$one/$two")) {
mkdir($_SERVER['DOCUMENT_ROOT'] . "/documents/$one/$two");
}
$three = mb_substr($name, 3, 1);
if (!is_dir($_SERVER['DOCUMENT_ROOT'] . "/documents/$one/$two/$three")) {
mkdir($_SERVER['DOCUMENT_ROOT'] . "/documents/$one/$two/$three");
}
$new_path = "$one/$two/$three/$name";
$document = "/documents/" . $new_path;
move_uploaded_file($_FILES['docFiles']['tmp_name'][$i], $_SERVER['DOCUMENT_ROOT'] . $document);
$manager = new DocumentManager((new TargetFactory())->getTarget($_POST['target_id'], $_POST['target_type']));
$manager->saveFileTo(
// хак 70lvl
trim(pathinfo(' ' . $_FILES['docFiles']['name'][$i], PATHINFO_FILENAME)),
$document,
$_POST['fold_id']
);
$dirObject = $manager->getDir($_POST['fold_id']);
$path = $manager->getParents($dirObject->getId());
$collection = $manager->getChildren($dirObject->getId());
$updateContent = true;
$markupId = "documentsContent" . $_POST['target_type'];
} else {
$result .= "Превышен размер файла " . $_FILES['docFiles']['name'][$i];
}
}
?>
<script type="text/javascript">
if (parent.document.getElementById('doc-loader')) {
parent.document.getElementById('doc-loader').style.backgroundImage = '';
}
if (parent.document.getElementById('doc-progress-loader')) {
parent.document.getElementById('doc-progress-loader').style.backgroundImage = '';
}
if (parent.document.getElementById('doc-plus-loader')) {
parent.document.getElementById('doc-plus-loader').style.backgroundImage = '';
}
<?php if ($updateContent) { ?>
parent.document.getElementById('<?php echo $markupId; ?>').innerHTML = '<?php include($_SERVER['DOCUMENT_ROOT']."/admin/documentsWidget.php"); ?>';
<?php } ?>
parent.document.getElementById('upload-docs-form').target = '';
parent.document.getElementById('upload-docs-form').action = '';
parent.document.getElementById('upload-docs-button').disabled = false;
parent.document.getElementById('upload-progress-form').target = '';
parent.document.getElementById('upload-progress-form').action = '';
parent.document.getElementById('upload-progress-button').disabled = false;
parent.document.getElementById('upload-plus-form').target = '';
parent.document.getElementById('upload-plus-form').action = '';
parent.document.getElementById('upload-plus-button').disabled = false;
</script>