openstamanager/editor.php

540 lines
19 KiB
PHP
Raw Normal View History

<?php
include_once __DIR__.'/core.php';
use Carbon\Carbon;
// Disabilitazione dei campi
$read_only = $structure->permission == 'r';
2019-07-26 11:57:59 +02:00
if (empty($id_record) && !empty($id_module) && empty($id_plugin)) {
redirect(ROOTDIR.'/controller.php?id_module='.$id_module);
2019-07-26 11:57:59 +02:00
} elseif (empty($id_record) && empty($id_module) && empty($id_plugin)) {
redirect(ROOTDIR.'/index.php');
}
2018-06-26 09:41:43 +02:00
include_once App::filepath('include|custom|', 'top.php');
2019-07-26 11:57:59 +02:00
if (!empty($id_record)) {
Util\Query::setSegments(false);
$query = Util\Query::getQuery($structure, [
'id' => $id_record,
]);
Util\Query::setSegments(true);
}
2019-07-23 17:09:10 +02:00
$query = str_replace(['AND `deleted_at` IS NULL', '`deleted_at` IS NULL AND', '`deleted_at` IS NULL', 'AND deleted_at IS NULL', 'deleted_at IS NULL AND', 'deleted_at IS NULL'], '', $query);
2019-07-05 18:29:14 +02:00
2019-02-18 09:25:31 +01:00
$has_access = !empty($query) ? $dbo->fetchNum($query) !== 0 : true;
2019-02-01 17:44:31 +01:00
if ($has_access) {
// Inclusione gli elementi fondamentali
2019-07-05 18:29:14 +02:00
include_once DOCROOT.'/actions.php';
}
2019-02-01 17:44:31 +01:00
if (empty($record) || !$has_access) {
echo '
2019-01-05 10:37:13 +01:00
<div class="text-center">
<h3 class="text-muted">'.
'<i class="fa fa-question-circle"></i> '.tr('Record non trovato').'
<br><br>
<small class="help-block">'.tr('Stai cercando di accedere ad un record eliminato o non presente').'.</small>
2019-01-05 10:37:13 +01:00
</h3>
<br>
<a class="btn btn-default" href="'.ROOTDIR.'/controller.php?id_module='.$id_module.'">
<i class="fa fa-chevron-left"></i> '.tr('Indietro').'
</a>
</div>';
} else {
2019-02-01 17:44:31 +01:00
// Widget in alto
echo '{( "name": "widgets", "id_module": "'.$id_module.'", "id_record": "'.$id_record.'", "position": "top", "place": "editor" )}';
$advanced_sessions = setting('Attiva notifica di presenza utenti sul record');
if (!empty($advanced_sessions)) {
$dbo->query('DELETE FROM zz_semaphores WHERE id_utente='.prepare(Auth::user()['id']).' AND posizione='.prepare($id_module.', '.$id_record));
$dbo->query('INSERT INTO zz_semaphores (id_utente, posizione, updated) VALUES ('.prepare(Auth::user()['id']).', '.prepare($id_module.', '.$id_record).', NOW())');
echo '
<div class="box box-warning box-solid text-center info-active hide">
<div class="box-header with-border">
<h3 class="box-title"><i class="fa fa-warning"></i> '.tr('Attenzione!').'</h3>
</div>
<div class="box-body">
<p>'.tr('I seguenti utenti stanno visualizzando questa pagina').':</p>
<ul class="list">
</ul>
<p>'.tr('Prestare attenzione prima di effettuare modifiche, poichè queste potrebbero essere perse a causa di multipli salvataggi contemporanei').'.</p>
</div>
</div>';
}
2020-07-21 08:31:44 +02:00
// Menu laterale per la visualizzazione dei plugin
echo '
2020-07-31 11:33:00 +02:00
<aside class="control-sidebar control-sidebar-light">
<h4 class="text-center">'.tr('Plugin disponibili').'</h4>
<ul class="nav nav-pills nav-stacked">
<li data-toggle="control-sidebar" class="active">
<a data-toggle="tab" href="#tab_0">
<i class="'.$structure['icon'].'"></i> '.$structure['title'].'
</a>
</li>';
2020-07-21 08:31:44 +02:00
// Tab dei plugin
$plugins = $dbo->fetchArray('SELECT id, title FROM zz_plugins WHERE idmodule_to='.prepare($id_module)." AND position='tab' AND enabled = 1 ORDER BY zz_plugins.order DESC");
foreach ($plugins as $plugin) {
2018-07-13 20:17:20 +02:00
echo '
2020-07-31 11:33:00 +02:00
<li data-toggle="control-sidebar">
<a data-toggle="tab" href="#tab_'.$plugin['id'].'" id="link-tab_'.$plugin['id'].'">
'.$plugin['title'].'
</a>
</li>';
2018-07-13 20:17:20 +02:00
}
2019-07-26 11:57:59 +02:00
// Tab per le note interne
2019-07-30 16:50:10 +02:00
if ($structure->permission != '-' && $structure->use_notes) {
$notes = $structure->recordNotes($id_record);
2019-07-26 11:57:59 +02:00
echo '
2020-07-31 11:33:00 +02:00
<li data-toggle="control-sidebar" class="bg-info">
<a data-toggle="tab" href="#tab_note" id="link-tab_note">
'.tr('Note interne').'
<span class="badge">'.($notes->count() ?: '').'</span>
2019-07-30 16:50:10 +02:00
</a>
2020-07-31 11:33:00 +02:00
</li>';
2019-07-30 16:50:10 +02:00
}
// Tab per le checklist
if ($structure->permission != '-' && $structure->use_checklists) {
echo '
2020-07-31 11:33:00 +02:00
<li data-toggle="control-sidebar" class="bg-success">
<a data-toggle="tab" href="#tab_checks" id="link-tab_checks">'.tr('Checklist').'</a>
</li>';
2019-07-26 11:57:59 +02:00
}
2020-07-21 08:31:44 +02:00
// Tab per le informazioni sulle operazioni
if (Auth::admin()) {
echo '
2020-07-31 11:33:00 +02:00
<li data-toggle="control-sidebar" class="bg-warning">
<a data-toggle="tab" href="#tab_info" id="link-tab_info">
'.tr('Info').'
</a>
</li>';
2020-07-21 08:31:44 +02:00
}
2020-07-21 08:31:44 +02:00
echo '
2020-07-31 11:33:00 +02:00
</ul>
</aside>
2020-07-21 08:31:44 +02:00
2020-07-31 11:33:00 +02:00
<div class="control-sidebar-bg"></div>
<div class="nav-tabs-custom">
<ul class="nav nav-tabs pull-right" id="tabs" role="tablist">
<li class="pull-left active header">
<a data-toggle="tab" href="#tab_0">
2020-07-21 08:31:44 +02:00
<i class="'.$structure['icon'].'"></i> '.$structure['title'];
// Pulsante "Aggiungi" solo se il modulo è di tipo "table" e se esiste il template per la popup
if ($structure->hasAddFile() && $structure->permission == 'rw') {
echo '
2020-07-21 08:31:44 +02:00
<button type="button" class="btn btn-primary" data-toggle="modal" data-title="'.tr('Aggiungi').'..." data-href="add.php?id_module='.$id_module.'&id_plugin='.$id_plugin.'"><i class="fa fa-plus"></i></button>';
}
echo '
2020-07-21 08:31:44 +02:00
</a>
</li>
<li>
2020-07-31 11:33:00 +02:00
<a data-toggle="control-sidebar" style="cursor: pointer">'.tr('Plugin').'</a>
2020-07-21 08:31:44 +02:00
</li>
</ul>
<div class="tab-content">
<div id="tab_0" class="tab-pane active">';
2019-07-08 12:25:51 +02:00
if (!empty($record['deleted_at'])) {
2019-07-23 16:12:46 +02:00
$operation = $dbo->fetchOne("SELECT zz_operations.created_at, username FROM zz_operations INNER JOIN zz_users ON zz_operations.id_utente = zz_users.id WHERE op='delete' AND id_module=".prepare($id_module).' AND id_record='.prepare($id_record).' ORDER BY zz_operations.created_at DESC');
2020-03-18 22:31:01 +01:00
$info = tr('Il record è stato eliminato il <b>_DATE_</b> da <b>_USER_</b>', [
2020-03-18 22:37:08 +01:00
'_DATE_' => (($operation['created_at']) ? Translator::timestampToLocale($operation['created_at']) : Translator::timestampToLocale($record['deleted_at'])),
2020-03-18 22:31:01 +01:00
'_USER_' => ((!empty($operation['username'])) ? $operation['username'] : 'N.D.'),
]).'. ';
2019-07-05 18:29:14 +02:00
echo '
<div class="alert alert-warning">
2019-07-23 16:12:46 +02:00
<div class="row" >
<div class="col-md-8">
<i class="fa fa-warning"></i> '.$info.'
2019-07-23 12:13:58 +02:00
</div>
</div>
2019-07-05 18:29:14 +02:00
</div>
2020-02-24 15:37:27 +01:00
2019-07-05 18:29:14 +02:00
<script>
2020-02-24 15:37:27 +01:00
$(document).ready(function(){
2019-07-05 18:29:14 +02:00
$("#restore").click(function(){
$("input[name=op]").attr("value", "restore");
$("#submit").trigger("click");
})
});
</script>';
}
// Pulsanti di default
echo '
2018-02-23 09:49:31 +01:00
<div id="pulsanti">
<a class="btn btn-warning" href="'.ROOTDIR.'/controller.php?id_module='.$id_module.'">
<i class="fa fa-chevron-left"></i> '.tr("Torna all'elenco").'
</a>
<div class="pull-right">
{( "name": "button", "type": "print", "id_module": "'.$id_module.'", "id_record": "'.$id_record.'" )}
{( "name": "button", "type": "email", "id_module": "'.$id_module.'", "id_record": "'.$id_record.'" )}
<a class="btn btn-success" id="'.(!empty($record['deleted_at']) ? 'restore' : 'save').'">
<i class="fa fa-'.(!empty($record['deleted_at']) ? 'undo' : 'check').'"></i> '.(!empty($record['deleted_at']) ? tr('Salva e Ripristina') : tr('Salva')).'
</a>
</div>
</div>
<script>
$(document).ready(function(){
var form = $("#module-edit").find("form").first();
// Aggiunta del submit
form.prepend(\'<button type="submit" id="submit" class="hide"></button>\');
$("#save").click(function(){
2019-07-05 17:10:20 +02:00
//submitAjax(form);
2020-02-24 15:37:27 +01:00
$("#submit").trigger("click");
2018-02-23 09:49:31 +01:00
});';
// Pulsanti dinamici
if (!isMobile()) {
echo '
$("#pulsanti").affix({
offset: {
top: 200
}
});
2018-06-22 17:04:37 +02:00
if ($("#pulsanti").hasClass("affix")) {
$("#pulsanti").css("width", $("#tab_0").css("width"));
}
$("#pulsanti").on("affix.bs.affix", function(){
$("#pulsanti").css("width", $("#tab_0").css("width"));
});
$("#pulsanti").on("affix-top.bs.affix", function(){
$("#pulsanti").css("width", "100%");
2018-02-23 09:49:31 +01:00
});';
}
echo '
});
</script>
<div class="clearfix"></div>
<br>';
// Pulsanti personalizzati
2018-09-19 10:44:32 +02:00
$buttons = $structure->filepath('buttons.php');
if (!empty($buttons)) {
2018-07-19 12:47:28 +02:00
ob_start();
include $buttons;
$buttons = ob_get_clean();
echo '
<div class="pull-right" id="pulsanti-modulo">
'.$buttons.'
</div>
<div class="clearfix"></div>
<br>';
}
// Contenuti del modulo
echo '
<div id="module-edit">';
2018-09-19 10:44:32 +02:00
include $structure->getEditFile();
echo '
</div>
</div>';
// Campi personalizzati
echo '
<div class="hide" id="custom_fields_top-edit">
{( "name": "custom_fields", "id_module": "'.$id_module.'", "id_record": "'.$id_record.'", "position": "top" )}
</div>
<div class="hide" id="custom_fields_bottom-edit">
{( "name": "custom_fields", "id_module": "'.$id_module.'", "id_record": "'.$id_record.'" )}
</div>
<script>
$(document).ready(function(){
2019-07-26 17:40:52 +02:00
cleanup_inputs();
2020-02-24 15:37:27 +01:00
2019-07-26 17:40:52 +02:00
var form = $("#module-edit").find("form").first();
2020-02-24 15:37:27 +01:00
// Campi a inizio form
form.prepend($("#custom_fields_top-edit").html());
// Campi a fine form
var last = form.find(".panel").last();
2018-09-24 10:51:48 +02:00
if (!last.length) {
last = form.find(".box").last();
}
if (!last.length) {
last = form.find(".row").eq(-2);
}
2020-02-24 15:37:27 +01:00
2019-07-26 17:40:52 +02:00
last.after($("#custom_fields_bottom-edit").html());
restart_inputs();
});
</script>';
2019-07-30 16:50:10 +02:00
if ($structure->permission != '-' && $structure->use_notes) {
2019-07-26 11:57:59 +02:00
echo '
<div id="tab_note" class="tab-pane">';
2019-07-30 16:50:10 +02:00
include DOCROOT.'/plugins/notes.php';
2019-07-26 11:57:59 +02:00
2019-07-30 16:50:10 +02:00
echo '
</div>';
}
2019-07-26 11:57:59 +02:00
2019-07-30 16:50:10 +02:00
if ($structure->permission != '-' && $structure->use_checklists) {
echo '
<div id="tab_checks" class="tab-pane">';
2019-07-26 11:57:59 +02:00
2019-07-30 16:50:10 +02:00
include DOCROOT.'/plugins/checks.php';
2019-07-26 11:57:59 +02:00
echo '
</div>';
}
2018-07-13 20:17:20 +02:00
// Informazioni sulle operazioni
if (Auth::admin()) {
echo '
<div id="tab_info" class="tab-pane">';
2018-07-13 20:17:20 +02:00
$operations = $dbo->fetchArray('SELECT `zz_operations`.*, `zz_users`.`username` FROM `zz_operations` JOIN `zz_users` ON `zz_operations`.`id_utente` = `zz_users`.`id` WHERE id_module = '.prepare($id_module).' AND id_record = '.prepare($id_record).' ORDER BY `created_at` ASC LIMIT 200');
if (!empty($operations)) {
echo '
<ul class="timeline">';
foreach ($operations as $operation) {
$description = $operation['op'];
$icon = 'pencil-square-o';
$color = null;
$timeline_class = null;
switch ($operation['op']) {
case 'add':
$description = tr('Creazione');
$icon = 'plus';
$color = 'success';
break;
case 'update':
$description = tr('Modifica');
$icon = 'pencil';
$color = 'info';
break;
case 'delete':
$description = tr('Eliminazione');
$icon = 'times';
$color = 'danger';
break;
case 'copy':
$description = tr('Duplicato');
$icon = 'clone';
$color = 'info';
break;
default:
$timeline_class = ' class="timeline-inverted"';
break;
}
echo '
<li '.$timeline_class.'>
2018-07-14 10:59:14 +02:00
<div class="timeline-badge '.$color.'"><i class="fa fa-'.$icon.'"></i></div>
<div class="timeline-panel">
<div class="timeline-heading">
<div class="row">
<div class="col-md-8">
<h4 class="timeline-title">'.$description.'</h4>
</div>
<div class="col-md-4 text-right">
<p><small class="label label-default tip" title="'.Translator::timestampToLocale($operation['created_at']).'"><i class="fa fa-clock-o"></i> '.Carbon::parse($operation['created_at'])->diffForHumans().'</small></p>
<p><small class="label label-default"><i class="fa fa-user"></i> '.$operation['username'].'</small></p>
</div>
</div>
2018-07-14 10:59:14 +02:00
</div>
<div class="timeline-body">
</div>
<div class="timeline-footer">
2018-07-14 10:59:14 +02:00
</div>
</div>
</li>';
}
2018-07-13 20:17:20 +02:00
2019-07-30 16:50:10 +02:00
echo '
</ul>';
} else {
echo '
<div class="alert alert-info">
<i class="fa fa-info-circle"></i>
<b>'.tr('Informazione:').'</b> '.tr('Nessun log disponibile per questa scheda').'.
</div>';
}
2019-07-26 11:57:59 +02:00
echo '
</div>';
2018-07-13 20:17:20 +02:00
}
// Plugin
2018-07-18 15:20:10 +02:00
$module_record = $record;
foreach ($plugins as $plugin) {
2018-07-18 15:20:10 +02:00
$record = $module_record;
echo '
<div id="tab_'.$plugin['id'].'" class="tab-pane">';
$id_plugin = $plugin['id'];
2019-07-05 18:29:14 +02:00
include DOCROOT.'/include/manager.php';
echo '
</div>';
}
2018-07-18 15:20:10 +02:00
$record = $module_record;
echo '
</div>
</div>';
}
2018-07-09 12:57:55 +02:00
redirectOperation($id_module, isset($id_parent) ? $id_parent : $id_record);
2018-02-22 12:35:22 +01:00
// Widget in basso
echo '{( "name": "widgets", "id_module": "'.$id_module.'", "id_record": "'.$id_record.'", "position": "right", "place": "editor" )}';
2019-01-05 10:37:13 +01:00
if (!empty($record)) {
echo '
<hr>
<a class="btn btn-default" href="'.ROOTDIR.'/controller.php?id_module='.$id_module.'">
<i class="fa fa-chevron-left"></i> '.tr('Indietro').'
</a>';
}
echo '
<script>';
// Se l'utente ha i permessi in sola lettura per il modulo, converto tutti i campi di testo in span
2018-07-09 16:12:27 +02:00
if ($read_only || !empty($block_edit)) {
$not = $read_only ? '' : '.not(".unblockable")';
2018-07-04 12:57:53 +02:00
echo '
$(document).ready(function(){
$("input, textarea, select", "section.content")'.$not.'.attr("readonly", "true");
2020-08-07 12:28:05 +02:00
$("select, input[type=checkbox]", "section.content")'.$not.'.prop("disabled", true);
$(".checkbox-buttons label", "section.content")'.$not.'.addClass("disabled");
';
2018-07-09 16:12:27 +02:00
if ($read_only) {
echo '
$("a.btn, button, input[type=button], input[type=submit]", "section.content").hide();
$("a.btn-info, button.btn-info, input[type=button].btn-info", "section.content").show();';
2018-07-09 16:12:27 +02:00
}
2018-07-04 12:57:53 +02:00
2018-07-09 16:12:27 +02:00
echo '
2018-07-04 12:57:53 +02:00
});';
}
?>
var content_was_modified = false;
//controllo se digito qualche valore o cambio qualche select
$("input, textarea, select").bind("change paste keyup", function(event) {
2020-08-07 12:28:05 +02:00
if (event.keyCode >= 32) {
content_was_modified = true;
}
});
$(".superselect, .superselectajax").on("change", function (e) {
content_was_modified = true;
});
//tolgo il controllo se sto salvando
$(".btn-success, button[type=submit]").bind("click", function() {
content_was_modified = false;
});
2020-08-07 12:28:05 +02:00
$("form").bind("submit", function() {
content_was_modified = false;
2020-08-07 12:28:05 +02:00
});
// questo controllo blocca il modulo vendita al banco, dopo la lettura con barcode, appare il messaggio di conferma
2020-08-07 12:28:05 +02:00
window.onbeforeunload = function(e) {
if(content_was_modified) {
var dialogText = "Uscire senza salvare?";
e.returnValue = dialogText;
$("#main_loading").fadeOut();
return dialogText;
}
};
window.addEventListener("unload", function(e) {
$("#main_loading").show();
});
<?php
2018-08-28 15:54:29 +02:00
if (!empty($advanced_sessions)) {
?>
function getActiveUsers(){
2018-08-28 15:54:29 +02:00
$.getJSON('<?php echo ROOTDIR; ?>/ajax.php?op=active_users', {
id_module: <?php echo $id_module; ?>,
id_record: <?php echo $id_record; ?>
},
function(data) {
if (data.length != 0) {
$(".info-active").removeClass("hide");
$(".info-active .list").html("");
$.each( data, function( key, val ) {
$(".info-active .list").append("<li>"+val.username+"</li>");
});
}
else $(".info-active").addClass("hide");
});
}
getActiveUsers();
2018-08-28 15:54:29 +02:00
setInterval(getActiveUsers, <?php echo setting('Timeout notifica di presenza (minuti)') * 60 * 1000; ?>);
<?php
}
?>
</script>
<?php
2018-06-26 09:41:43 +02:00
include_once App::filepath('include|custom|', 'bottom.php');