openstamanager/modules/viste/fields.php

283 lines
13 KiB
PHP
Raw Normal View History

2019-05-10 23:47:45 +02:00
<?php
2020-09-07 15:04:06 +02:00
/*
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
2021-01-20 15:08:51 +01:00
* Copyright (C) DevCode s.r.l.
2020-09-07 15:04:06 +02:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
2019-05-10 23:47:45 +02:00
2024-03-13 17:32:07 +01:00
use Models\View;
2019-05-10 23:47:45 +02:00
echo '
<form action="" method="post" role="form">
<input type="hidden" name="backto" value="record-edit">
<input type="hidden" name="op" value="fields">
<div class="row">
<div class="col-md-9">
<div class="data">';
$key = 0;
2024-03-13 17:32:07 +01:00
$fields = View::where('id_module', '=', $record->id)->orderBy('order', 'asc')->get();
2024-03-12 11:32:08 +01:00
2019-05-10 23:47:45 +02:00
foreach ($fields as $key => $field) {
2024-03-25 17:34:39 +01:00
$editable = !($field->default && $enable_readonly);
2019-05-10 23:47:45 +02:00
echo '
2024-03-25 17:34:39 +01:00
<div class="box collapsed-box box-'.($field->visible ? 'success' : 'danger').'">
2019-05-10 23:47:45 +02:00
<div class="box-header with-border">
2019-11-23 08:23:34 +01:00
<h3 class="box-title">'.
2024-04-13 20:28:48 +02:00
$field->getTranslation('name').' <small class="text-muted tip" title="'.(new Carbon\Carbon($field->updated_at))->format('d/m/Y H:i').'">('.tr('modificato').' '.(new Carbon\Carbon($field->updated_at))->diffForHumans().')</small>
2019-11-23 08:23:34 +01:00
</h3>
<div class="box-tools pull-right">
<button type="button" class="btn btn-box-tool" data-widget="collapse">
<i class="fa fa-plus"></i>
2019-11-23 08:23:34 +01:00
</button>
</div>
2019-05-10 23:47:45 +02:00
</div>
2024-03-25 17:34:39 +01:00
<div id="field-'.$field->id.'" class="box-body collapse">
2019-05-10 23:47:45 +02:00
<div class="row">
2024-03-25 17:34:39 +01:00
<input type="hidden" value="'.$field->id.'" name="id['.$key.']">
2020-04-27 10:26:40 +02:00
2019-05-10 23:47:45 +02:00
<div class="col-md-12">
2024-03-25 17:34:39 +01:00
{[ "type": "text", "label": "'.tr('Nome').'", "name": "name['.$key.']", "value": "'.$field->getTranslation('name').'", "readonly": "'.(!$editable).'", "help": "'.tr('Nome con cui il campo viene identificato e visualizzato nella tabella').'" ]}
2019-05-10 23:47:45 +02:00
</div>
</div>
2020-04-27 10:26:40 +02:00
2019-05-10 23:47:45 +02:00
<div class="row">
<div class="col-md-12">
2022-12-01 17:44:15 +01:00
'.input([
2024-04-09 12:18:08 +02:00
'type' => 'textarea',
'label' => tr('Query prevista'),
'name' => 'query['.$key.']',
'required' => 1,
'readonly' => ''.(!$editable).'',
'value' => $field->query,
'help' => tr('Nome effettivo del campo sulla tabella oppure subquery che permette di ottenere il valore del campo.').'<br>'.tr('ATTENZIONE: utilizza sempre i caratteri < o > seguiti da spazio!'),
]).'
2019-05-10 23:47:45 +02:00
</div>
</div>
2020-04-27 10:26:40 +02:00
2019-05-10 23:47:45 +02:00
<div class="row">
<div class="col-md-6">
2024-03-22 15:52:24 +01:00
{[ "type": "select", "label": "'.tr('Gruppi con accesso').'", "name": "gruppi['.$key.'][]", "multiple": "1", "values": "query=SELECT `zz_groups`.`id`, `name` AS descrizione FROM `zz_groups` LEFT JOIN `zz_groups_lang` ON (`zz_groups`.`id` = `zz_groups_lang`.`id_record` AND `zz_groups_lang`.`id_lang` = '.prepare(Models\Locale::getDefault()->id).') ORDER BY `zz_groups`.`id` ASC", "value": "';
2024-03-25 17:34:39 +01:00
$results = $dbo->fetchArray('SELECT GROUP_CONCAT(DISTINCT `id_gruppo` SEPARATOR \',\') AS gruppi FROM `zz_group_view` WHERE `id_vista`='.prepare($field->id));
2019-05-10 23:47:45 +02:00
echo $results[0]['gruppi'].'"';
echo ', "help": "'.tr('Gruppi di utenti in grado di visualizzare questo campo').'" ]}
</div>
2020-04-27 10:26:40 +02:00
2019-05-10 23:47:45 +02:00
<div class="col-xs-12 col-md-6">
2024-03-25 17:34:39 +01:00
{[ "type": "select", "label": "'.tr('Visibilità').'", "name": "visible['.$key.']", "values": "list=\"0\":\"'.tr('Nascosto (variabili di stato)').'\",\"1\": \"'.tr('Visibile nella sezione').'\"", "value": "'.$field->visible.'", "help": "'.tr('Stato del campo: visibile nella tabella oppure nascosto').'" ]}
2019-05-10 23:47:45 +02:00
</div>
</div>
2020-04-27 10:26:40 +02:00
2019-05-10 23:47:45 +02:00
<div class="row">
<div class="col-md-4">
2024-03-25 17:34:39 +01:00
{[ "type": "checkbox", "label": "'.tr('Ricercabile').'", "name": "search['.$key.']", "value": "'.$field->search.'", "help": "'.tr('Indica se il campo è ricercabile').'" ]}
2019-05-10 23:47:45 +02:00
</div>
2020-04-27 10:26:40 +02:00
<div class="col-md-4">
2024-03-25 17:34:39 +01:00
{[ "type": "checkbox", "label": "'.tr('Ricerca lenta').'", "name": "slow['.$key.']", "value": "'.$field->slow.'", "help": "'.tr("Indica se la ricerca per questo campo è lenta (da utilizzare nel caso di evidenti rallentamenti, mostra solo un avviso all'utente").'" ]}
2019-05-10 23:47:45 +02:00
</div>
2020-04-27 10:26:40 +02:00
<div class="col-md-4">
2024-03-25 17:34:39 +01:00
{[ "type": "checkbox", "label": "'.tr('Sommabile').'", "name": "sum['.$key.']", "value": "'.$field->summable.'", "help": "'.tr('Indica se il campo è da sommare').'" ]}
2019-05-10 23:47:45 +02:00
</div>
</div>
2022-03-07 16:40:03 +01:00
<div class="row">
<div class="col-md-4">
2024-03-25 17:34:39 +01:00
{[ "type": "checkbox", "label": "'.tr('Formattazione automatica').'", "name": "format['.$key.']", "value": "'.$field->format.'", "help": "'.tr('Indica se il campo deve essere formattabile in modo automatico, per esempio valori numerici o date.').'" ]}
</div>
2020-04-27 10:26:40 +02:00
<div class="col-md-4">
2024-03-25 17:34:39 +01:00
{[ "type": "checkbox", "label": "'.tr('Utilizza HTML').'", "name": "html_format['.$key.']", "value": "'.$field->html_format.'", "help": "'.tr('Indica se il campo deve mantenere la formattazione HTML. Impostazione utile per i campi di testo con editor.').'" ]}
2019-05-10 23:47:45 +02:00
</div>
</div>
2020-04-27 10:26:40 +02:00
2019-05-10 23:47:45 +02:00
<div class="row">
<div class="col-md-6">
2024-03-25 17:34:39 +01:00
{[ "type": "text", "label": "'.tr('Ricerca tramite').'", "name": "search_inside['.$key.']", "value": "'.$field->search_inside.'", "readonly": "'.(!$editable).'", "help": "'.tr('Query personalizzata per la ricerca (consigliata per colori e icone)').'.<br>'.tr('ATTENZIONE: utilizza sempre i caratteri < o > seguiti da spazio!').'" ]}
2019-05-10 23:47:45 +02:00
</div>
2020-04-27 10:26:40 +02:00
2019-05-10 23:47:45 +02:00
<div class="col-md-6">
2024-03-25 17:34:39 +01:00
{[ "type": "text", "label": "'.tr('Ordina tramite').'", "name": "order_by['.$key.']", "value": "'.$field->order_by.'", "readonly": "'.(!$editable).'", "help": "'.tr("Query personalizzata per l'ordinamento (date e numeri formattati tramite query)").'.<br>'.tr('ATTENZIONE: utilizza sempre i caratteri < o > seguiti da spazio!').'" ]}
2019-05-10 23:47:45 +02:00
</div>
</div>';
2024-04-09 12:18:08 +02:00
if ($editable) {
echo '
<a class="btn btn-danger ask pull-right" data-backto="record-edit" data-id="'.$field->id.'">
<i class="fa fa-trash"></i> '.tr('Elimina').'
</a>';
2024-04-09 12:18:08 +02:00
}
echo '
2019-05-10 23:47:45 +02:00
</div>
</div>';
}
echo '
</div>
<div class="row">
<div class="col-md-12 text-right">
<button type="button" class="btn btn-info" id="add">
<i class="fa fa-plus"></i> '.tr('Aggiungi nuovo campo').'
</button>
2020-04-27 10:26:40 +02:00
2019-05-10 23:47:45 +02:00
<button type="submit" class="btn btn-success">
<i class="fa fa-check"></i> '.tr('Salva').'
</button>
</div>
</div>
</div>
<div class="col-md-3">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">'.tr('Ordine di visualizzazione').' <span class="tip pull-right" title="'.tr('Trascina per ordinare le colonne').'."><i class="fa fa-question-circle-o"></i></span></h3>
</div>
2020-04-27 10:26:40 +02:00
2019-05-10 23:47:45 +02:00
<div class="panel-body sortable">';
foreach ($fields as $field) {
echo '
2024-03-25 17:34:39 +01:00
<p class="clickable no-selection" data-id="'.$field->id.'">
<i class="fa fa-sort"></i>
2019-05-10 23:47:45 +02:00
';
2024-03-25 17:34:39 +01:00
if ($field->visible) {
echo '<strong class="text-success">'.$field->getTranslation('name').'</strong>';
2019-05-10 23:47:45 +02:00
} else {
2024-03-25 17:34:39 +01:00
echo '<span class="text-danger">'.$field->getTranslation('name').'</span>';
2019-05-10 23:47:45 +02:00
}
echo '
</p>';
}
echo '
</div>
</div>
</div>
</div>
</form>';
echo '
<form class="hide" id="template">
<div class="box">
<div class="box-header with-border">
<h3 class="box-title">'.tr('Nuovo campo').'</h3>
</div>
<div class="box-body">
<div class="row">
<input type="hidden" value="" name="id[-id-]">
<div class="col-md-12">
{[ "type": "text", "label": "'.tr('Nome').'", "name": "name[-id-]" ]}
</div>
</div>
<div class="row">
<div class="col-md-12">
{[ "type": "textarea", "label": "'.tr('Query prevista').'", "name": "query[-id-]" ]}
</div>
</div>
<div class="row">
<div class="col-md-6">
2024-03-22 15:52:24 +01:00
{[ "type": "select", "label": "'.tr('Gruppi con accesso').'", "name": "gruppi[-id-][]", "multiple": "1", "values": "query=SELECT `zz_groups`.`id`, `name` AS descrizione FROM `zz_groups` LEFT JOIN `zz_groups_lang` ON (`zz_groups`.`id` = `zz_groups_lang`.`id_record` AND `zz_groups_lang`.`id_lang` = '.prepare(Models\Locale::getDefault()->id).') ORDER BY `zz_groups`.`id` ASC" ]}
2019-05-10 23:47:45 +02:00
</div>
<div class="col-md-6">
{[ "type": "select", "label": "'.tr('Visibilità').'", "name": "visible[-id-]", "values": "list=\"0\":\"'.tr('Nascosto (variabili di stato)').'\",\"1\": \"'.tr('Visibile nella sezione').'\"" ]}
</div>
</div>
<div class="row">
2022-03-07 16:40:03 +01:00
<div class="col-md-4">
2019-05-10 23:47:45 +02:00
{[ "type": "checkbox", "label": "'.tr('Ricercabile').'", "name": "search[-id-]" ]}
</div>
2022-03-07 16:40:03 +01:00
<div class="col-md-4">
2019-05-10 23:47:45 +02:00
{[ "type": "checkbox", "label": "'.tr('Ricerca lenta').'", "name": "slow[-id-]" ]}
</div>
2022-03-07 16:40:03 +01:00
<div class="col-md-4">
2019-05-10 23:47:45 +02:00
{[ "type": "checkbox", "label": "'.tr('Sommabile').'", "name": "sum[-id-]" ]}
</div>
2022-03-07 16:40:03 +01:00
</div>
<div class="row">
<div class="col-md-4">
{[ "type": "checkbox", "label": "'.tr('Formattazione automatica').'", "name": "format[-id-]", "help": "'.tr('Indica se il campo deve essere formattabile in modo automatico, per esempio valori numerici o date.').'" ]}
</div>
2019-05-10 23:47:45 +02:00
2022-03-07 16:40:03 +01:00
<div class="col-md-4">
{[ "type": "checkbox", "label": "'.tr('Utilizza HTML').'", "name": "html_format[-id-]", "help": "'.tr('Indica se il campo deve mantenere la formattazione HTML. Impostazione utile per i campi di testo con editor.').'" ]}
2019-05-10 23:47:45 +02:00
</div>
</div>
<div class="row">
<div class="col-md-6">
{[ "type": "text", "label": "'.tr('Ricerca tramite').'", "name": "search_inside[-id-]" ]}
</div>
<div class="col-md-6">
{[ "type": "text", "label": "'.tr('Ordina tramite').'", "name": "order_by[-id-]" ]}
</div>
</div>
</div>
</div>
</form>';
echo '
<script>
var n = '.$key.';
$(document).on("click", "#add", function() {
2019-07-26 17:40:52 +02:00
cleanup_inputs();
2020-04-27 10:26:40 +02:00
2019-05-10 23:47:45 +02:00
n++;
var text = replaceAll($("#template").html(), "-id-", "" + n);
2020-04-27 10:26:40 +02:00
2019-05-10 23:47:45 +02:00
$(this).parent().parent().parent().find(".data").append(text);
2019-07-26 17:40:52 +02:00
restart_inputs();
2019-05-10 23:47:45 +02:00
});
2020-04-27 10:26:40 +02:00
$(document).ready(function() {
$("#save-buttons").hide();
2020-04-27 10:26:40 +02:00
sortable(".sortable", {
axis: "y",
cursor: "move",
dropOnEmpty: true,
scroll: true,
})[0].addEventListener("sortupdate", function(e) {
let order = $(".sortable p[data-id]").toArray().map(a => $(a).data("id"))
$.post(globals.rootdir + "/actions.php", {
id_module: globals.id_module,
id_record: globals.id_record,
op: "update_position",
order: order.join(","),
2019-05-10 23:47:45 +02:00
});
});
});
</script>';