gestione gare pubbliche
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 

200 righe
8.9 KiB

<?
if (!empty($onSuccessScript)) {
if (empty($uploaderID)) {
$uploaderID = generateStrongPassword(9,false,'lud');
}
$uploaderVarID = "_".preg_replace('/[^\w]/', '_', $uploaderID);
if (!isset($options)) {
$options = [];
}
if (!isset($options["allowedTypes"])) {
$options["allowedTypes"] = filesManager::acceptedFilesExtensions();
}
if (is_array($options["allowedTypes"])) {
$allowedTypesForLabel = implode(" ",$options["allowedTypes"]);
$options["allowedTypes"] = filesManager::extensionsArrayToRegex($options["allowedTypes"]);
}
?>
<div class="card card-body my-2">
<div class="col-12 dropper-parent">
<div id="<?= $uploaderVarID ?>-dropzone-attachment" class="dropper-dropzone" style="height:auto">
<div class="div-as-table">
<div class="cell text-break">
<? if (isset($options["maxNumberOfFiles"]) && $options["maxNumberOfFiles"] === 1) { ?>
<strong>
<span class="far fa-folder fa-2x"></span><br>
<?= __("Scegli file") ?>...
</strong>
<? } else { ?>
<span class="far fa-folder fa-2x"></span>
<h4><?= __("Trascina i files in questa area oppure clicca per selezionare un file...") ?></h4>
<? } ?>
</div>
<? if (!empty($options["maxFileSize"])) { ?>
<div class="text-center">
<strong><?= __("Dimensione massima").":" . human_filesize($options["maxFileSize"]) ?></strong>
</div>
<? } ?>
<? if (!empty($allowedTypesForLabel)) { ?>
<div class="text-center">
<small><?= __("Estensioni accettate")."<br>" .$allowedTypesForLabel ?></small>
</div>
<? } ?>
</div>
</div>
</div>
<div class="col-12 my-2">
<div id="<?= $uploaderVarID ?>-progress" class="progress">
<div class="progress-bar bg-info" role="progressbar" aria-valuemin="0" aria-valuemax="100"></div>
<input type="hidden" rel="S;0;0;A" value="OK" id="<?= $uploaderVarID ?>-upload-end" title="<?= __("Fine caricamento allegati") ?>">
</div>
<div class="py-2 text-center"><small id="<?= $uploaderID ?>-logs"></small></div>
</div>
</div>
<script src="/src/js/crypto-js.js"></script>
<script type="text/javascript">
var calculatedHash<?= $uploaderVarID ?> = {};
function startUpload<?= $uploaderVarID ?>() {
var files = resumable<?= $uploaderVarID ?>.files;
if (files.length > 0) {
var all = true;
for(i=0;i<files.length;i++) {
var file = files[i];
if (typeof calculatedHash<?= $uploaderVarID ?>[file.uniqueIdentifier] === "undefined") {
all = false;
}
}
if (all) {
resumable<?= $uploaderVarID ?>.upload();
}
}
}
var chunkSize = <?= DEVELOP_ENV ? 0.5*1024*1024 : 3*1024*1024 ?>;
var resumable<?= $uploaderVarID ?> = new Resumable({
chunkSize:chunkSize,
simultaneousUploads:1,
target:'/allegati/servers/resumable.php',
prioritizeFirstAndLastChunk:true,
throttleProgressCallbacks:1,
query: (file,chunk) => {
return {
checksum: calculatedHash<?= $uploaderVarID ?>[file.uniqueIdentifier],
uploaderId: "<?= $uploaderID ?>"
}
},
<? if (!empty($options["maxNumberOfFiles"])) { ?>
maxFiles: <?= $options["maxNumberOfFiles"] ?>,
<? } ?>
<? if (!empty($options["maxFileSize"])) { ?>
maxFileSize: <?= $options["maxFileSize"] ?>,
<? } ?>
});
if(!resumable<?= $uploaderVarID ?>.support) {
Swal({
title: '<strong>Il tuo browser non supporta la procedura di <u>upload dei file</u>.</strong>',
type: 'error',
html:
'<b>Ti consigliamo di aggiornare il browser in uso o di utilizzarne uno dei seguenti:</b> ' +
'<a href="http://www.google.it/intl/it/chrome/browser/">Google Chrome</a> oppure ' +
'<a href="http://www.mozilla.org/it/firefox/new/">Mozilla Firefox</a> '
});
}
resumable<?= $uploaderVarID ?>.assignBrowse($("#<?= $uploaderVarID ?>-dropzone-attachment"));
resumable<?= $uploaderVarID ?>.assignDrop($("#<?= $uploaderVarID ?>-dropzone-attachment"));
resumable<?= $uploaderVarID ?>.on('fileError', function(file, message){
if (typeof calculatedHash<?= $uploaderVarID ?>[file.uniqueIdentifier]) {
delete calculatedHash<?= $uploaderVarID ?>[file.uniqueIdentifier];
}
resumable<?= $uploaderVarID ?>.removeFile(file);
<? if (!empty($options["onErrorScript"])) {
echo $options["onErrorScript"];
} else { ?>
swal({
title: "<?= __("Attenzione!") ?>",
html: "<?= __("Si &egrave; verificato un errore nel caricamento del file. Si prega di riprovare!") ?><br>" + file.fileName ,
type: "warning",
confirmButtonText: "Ok",
confirmButtonClass: 'btn btn-warning',
});
<? } ?>
});
resumable<?= $uploaderVarID ?>.on('fileSuccess', function(file, message){
file.name = sanitize_string(window.htmlentities.decode(file.fileName));
<?= $onSuccessScript ?>
<? if (isset($options["maxNumberOfFiles"]) && $options["maxNumberOfFiles"] === 1) { ?>
$("#<?= $uploaderVarID ?>-dropzone-attachment").find(".cell").html("<strong class='text-primary'><span class='far fa-file'></span> "+file.name+"</strong>");
<? } ?>
});
resumable<?= $uploaderVarID ?>.on('fileProgress', function(file){
});
resumable<?= $uploaderVarID ?>.on('complete', function(){
$('#<?= $uploaderVarID ?>-progress .progress-bar').hide();
$('#<?= $uploaderVarID ?>-upload-end').val('OK');
$('#<?= $uploaderVarID ?>-progress .progress-bar').css('width', 0 + '%');
});
resumable<?= $uploaderVarID ?>.on('progress',function() {
progress = Math.floor(this.progress() * 100);
$('#<?= $uploaderVarID ?>-upload-end').val('');
$('#<?= $uploaderVarID ?>-progress .progress-bar').show();
$('#<?= $uploaderVarID ?>-progress .progress-bar').css('width', progress + '%');
});
resumable<?= $uploaderVarID ?>.on('pause', function(file){});
resumable<?= $uploaderVarID ?>.on('fileRetry', function(file){});
resumable<?= $uploaderVarID ?>.on('fileAdded', function(file) {
<? if (!empty($options["onFileAddScript"])) {
echo $options["onFileAddScript"];
} ?>
if (!(<?= $options["allowedTypes"] ?>).test(file.fileName)) {
swal({
title: "Attenzione!",
html: "Questo tipo di file non è valido! Il file non ha un'estenzione valida!<br>" + file.fileName,
type: "warning",
confirmButtonText: "Riprova",
confirmButtonClass: 'btn btn-outline-warning',
});
resumable<?= $uploaderVarID ?>.removeFile(file);
startUpload<?= $uploaderVarID ?>();
} else {
var hashChunkSize = chunkSize * 3;
var resumableFile = file;
var SHA256 = CryptoJS.algo.SHA256.create();
var binary = [];
var className;
className = file.uniqueIdentifier;
var currentChunk = 0;
var totalChunks = Math.ceil(file.size / hashChunkSize);
var loadNext = function() {
var reader = new FileReader();
reader.onload = function(evt) {
currentChunk++;
var wordArray = CryptoJS.lib.WordArray.create(evt.target.result);
SHA256.update(wordArray);
if (currentChunk < totalChunks) {
perc = Math.ceil(currentChunk * 100 / totalChunks);
if (perc > 99) {
perc = 99;
}
$('#<?= $uploaderVarID ?>-upload-end').val('');
$("#log-file-perc-"+className).html(perc + "%");
loadNext();
} else {
$("#log-file-"+className).remove();
checksum = SHA256.finalize().toString();
calculatedHash<?= $uploaderVarID ?>[resumableFile.uniqueIdentifier] = checksum;
startUpload<?= $uploaderVarID ?>();
}
};
var start = currentChunk * hashChunkSize,
end = ((start + hashChunkSize) >= file.size) ? file.size : start + hashChunkSize;
reader.readAsArrayBuffer(file.file.slice(start,end));
}
loadNext();
$("#<?= $uploaderID ?>-logs").append('<div id="log-file-'+className+'"><span class="fa fa-spinner fa-spin"></span> <?= __("Calcolo hash") ?>: '+ file.fileName+' <span id="log-file-perc-'+className+'"></span></div>');
}
});
</script>
<?
}
?>