diff --git a/actions.php b/actions.php index d442d4b27..05e80c3e0 100644 --- a/actions.php +++ b/actions.php @@ -39,13 +39,12 @@ if (filter('op') == 'link_file' || filter('op') == 'unlink_file') { else { // UPLOAD if (filter('op') == 'link_file' && !empty($_FILES) && !empty($_FILES['blob']['name'])) { - $nome = filter('nome_allegato'); $nome = !empty($nome) ? $nome : $_FILES['blob']['name']; - + $src = $_FILES['blob']['tmp_name']; $f = pathinfo($_FILES['blob']['name']); - + /* $allowed = [ // Image formats @@ -166,25 +165,18 @@ if (filter('op') == 'link_file' || filter('op') == 'unlink_file') { do { $filename = random_string().'.'.$f['extension']; } while (file_exists($upload_dir.'/'.$filename)); - - + // Creazione file fisico if (move_uploaded_file($src, $upload_dir.'/'.$filename)) { - - $dbo->insert('zz_files', [ + $dbo->insert('zz_files', [ 'nome' => $nome, 'filename' => $filename, 'original' => $_FILES['blob']['name'], 'id_module' => $id_module, 'id_record' => $id_record, - 'id_plugin' => $id_plugin, + 'id_plugin' => !empty($id_plugin) ? $id_plugin : null, ]); - /*$dbo->query('INSERT INTO zz_files(nome, filename, original, id_module, id_record, id_plugin) VALUES('.prepare($nome).','.prepare($filename).',"'.$_FILES['blob']['name'].'",'.prepare($id_module).','.prepare($id_record).','.prepare($id_plugin).')'); - - echo 'INSERT INTO zz_files(nome, filename, original, id_module, id_record, id_plugin) VALUES('.prepare($nome).','.prepare($filename).',"'.$_FILES['blob']['name'].'",'.prepare($id_module).','.prepare($id_record).','.prepare($id_plugin).')'; - exit;*/ - $_SESSION['infos'][] = tr('File caricato correttamente!'); } else { $_SESSION['errors'][] = tr('Errore durante il caricamento del file!'); diff --git a/src/HTMLBuilder/Manager/FileManager.php b/src/HTMLBuilder/Manager/FileManager.php index 38105a467..350261599 100644 --- a/src/HTMLBuilder/Manager/FileManager.php +++ b/src/HTMLBuilder/Manager/FileManager.php @@ -9,26 +9,24 @@ namespace HTMLBuilder\Manager; */ class FileManager implements ManagerInterface { - - /** - * Gestione "filelist_and_upload". + /** + * Gestione "filelist_and_upload". * Esempio: {( "name": "filelist_and_upload", "id_module": "2", "id_record": "1", "readonly": "false", "ajax": "true" )}. * * @param array $options * * @return string */ - public function manage($options) { - $options['readonly'] = ($options['readonly']=='true') ? true : false; + $options['readonly'] = ($options['readonly'] == 'true') ? true : false; $options['ajax'] = isset($options['ajax']) ? $options['ajax'] : false; - $options['showpanel'] = isset($options['showpanel']) ? $options['showpanel'] : true; + $options['showpanel'] = isset($options['showpanel']) ? $options['showpanel'] : true; $options['label'] = isset($options['label']) ? $options['label'] : tr('Nuovo allegato').':'; $dbo = \Database::getConnection(); -$result .= ' + $result .= '
'; @@ -42,10 +40,13 @@ $result .= ' } // Visualizzo l'elenco di file già caricati - if (!empty($options['id_plugin'])) - $rs = $dbo->fetchArray('SELECT * FROM zz_files WHERE id_module='.prepare($options['id_module']).' AND id_record='.prepare($options['id_record']).' AND id_plugin='.prepare($options['id_plugin'])); - else - $rs = $dbo->fetchArray('SELECT * FROM zz_files WHERE id_module='.prepare($options['id_module']).' AND id_record='.prepare($options['id_record']).' AND id_plugin = 0'); + $query = 'SELECT * FROM zz_files WHERE id_module='.prepare($options['id_module']).' AND id_record = '.prepare($options['id_record']).' AND id_plugin '; + if (!empty($options['id_plugin'])) { + $query .= ' = '.prepare($options['id_plugin']); + } else { + $query .= 'IS NULL'; + } + $rs = $dbo->fetchArray($query); if (!empty($rs)) { $result .= ' @@ -66,37 +67,41 @@ $result .= ' '.\Translator::timestampToLocale($r['created_at']).' - + '; - - - //Anteprime supportate dal browser - // - $extension = end((explode('.', $r['nome']))); - $supported_extensions = ['pdf','jpg','png','gif','jpeg','bmp']; - if ( in_array($extension, $supported_extensions)){ - $result .= " -
- - alt : ".$r['filename']." - plugin ".$extension." mancante. - -
- "; - }else{ - $result .= "\n"; - } - - if (!$options['readonly']){ - $result .= ' + + // Anteprime supportate dal browser + $extension = end((explode('.', $r['original']))); + $supported_extensions = ['pdf', 'jpg', 'png', 'gif', 'jpeg', 'bmp']; + if (in_array($extension, $supported_extensions)) { + $result .= ' +
+ + alt : '.$r['filename'].' + plugin '.$extension.' mancante. + +
+ + '; + } else { + $result .= ' + '; + } + + if (!$options['readonly']) { + $result .= ' '; - } - - $result .= ' + } + + $result .= ' '; } @@ -105,25 +110,23 @@ $result .= '

'; - }else{ - //in caso di readonly, se non è stato caricato nessun allegato mostro almeno box informativo - if ($options['readonly']){ - $result .= ' + } else { + // In caso di readonly, se non è stato caricato nessun allegato mostro almeno box informativo + if ($options['readonly']) { + $result .= '
'.tr('Nessun allegato è stato caricato', []).'.
'; - } - } + } + } - - if (!$options['readonly']){ - - // Form per l'upload di un nuovo file - $result .= ' + if (!$options['readonly']) { + // Form per l'upload di un nuovo file + $result .= ' '.$options['label'].'
- +
{[ "type": "text", "placeholder": "'.tr('Nome').'", "name": "nome_allegato", "id": "nome_allegato_'.$options['id_record'].((!empty($options['id_plugin'])) ? '_'.$options['id_plugin'] : '').'" ]}
@@ -131,17 +134,17 @@ $result .= '
{[ "type": "file", "placeholder": "'.tr('File').'", "name": "blob", "id": "blob_'.$options['id_record'].((!empty($options['id_plugin'])) ? '_'.$options['id_plugin'] : '').'", "required": 0 ]}
'; - - $result .= ' + + $result .= '
'; - - $result .= ' + + $result .= '
'; - } + } $result .= '