2017-08-04 16:28:16 +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/>.
|
|
|
|
*/
|
2017-08-04 16:28:16 +02:00
|
|
|
|
|
|
|
namespace HTMLBuilder\Wrapper;
|
|
|
|
|
2018-09-19 10:44:32 +02:00
|
|
|
use Modules;
|
|
|
|
|
2017-08-04 16:28:16 +02:00
|
|
|
/**
|
|
|
|
* @since 2.3
|
|
|
|
*/
|
|
|
|
class HTMLWrapper implements WrapperInterface
|
|
|
|
{
|
|
|
|
public function before(&$values, &$extras)
|
|
|
|
{
|
|
|
|
$result = '';
|
2022-07-13 22:39:47 +02:00
|
|
|
$extra_class = '';
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2022-06-03 12:59:42 +02:00
|
|
|
if( $values['type']=='checkbox' ){
|
2022-07-13 22:39:47 +02:00
|
|
|
$extra_class = 'checkbox-group';
|
2022-06-03 12:59:42 +02:00
|
|
|
}
|
|
|
|
|
2017-08-04 16:28:16 +02:00
|
|
|
// Valori particolari
|
2018-09-20 09:21:34 +02:00
|
|
|
$values['icon-before'] = isset($values['icon-before']) ? $this->parser($values, $extras, $values['icon-before']) : null;
|
|
|
|
$values['icon-after'] = isset($values['icon-after']) ? $this->parser($values, $extras, $values['icon-after']) : null;
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2022-07-30 15:33:03 +02:00
|
|
|
$result .= '
|
|
|
|
<div class="form-group '.$extra_class.'">';
|
|
|
|
|
2017-08-04 16:28:16 +02:00
|
|
|
// Generazione dell'etichetta
|
|
|
|
if (!empty($values['label'])) {
|
|
|
|
$result .= '
|
2017-09-15 09:48:56 +02:00
|
|
|
<label for="'.prepareToField($values['id']).'">'.(empty($values['help']) ? $values['label'] : '<span class="tip" title="'.prepareToField($values['help']).'">'.$values['label'].' <i class="fa fa-question-circle-o"></i></span>').'</label>';
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
|
|
|
|
2019-07-05 12:28:19 +02:00
|
|
|
if (!empty($values['icon-before']) || !empty($values['icon-after']) || !empty($values['validation'])) {
|
2017-08-04 16:28:16 +02:00
|
|
|
$result .= '
|
2019-07-30 16:51:33 +02:00
|
|
|
<div class="input-group has-feedback">';
|
2017-08-04 16:28:16 +02:00
|
|
|
|
|
|
|
if (!empty($values['icon-before'])) {
|
|
|
|
$result .= '
|
2018-10-25 16:17:52 +02:00
|
|
|
<span class="input-group-addon before'.(!empty($values['icon-custom']) ? ' '.$values['icon-custom'] : '').'">'.$values['icon-before'].'</span>';
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function after(&$values, &$extras)
|
|
|
|
{
|
2019-07-05 12:28:19 +02:00
|
|
|
$rand = rand(0, 99);
|
|
|
|
$pseudo_id = $values['id'].$rand;
|
|
|
|
|
2017-08-04 16:28:16 +02:00
|
|
|
$result = '';
|
|
|
|
|
2019-07-05 12:28:19 +02:00
|
|
|
if (!empty($values['icon-before']) || !empty($values['icon-after']) || !empty($values['validation'])) {
|
2017-08-04 16:28:16 +02:00
|
|
|
if (!empty($values['icon-after'])) {
|
|
|
|
$result .= '
|
2018-10-25 16:17:52 +02:00
|
|
|
<span class="input-group-addon after'.(!empty($values['icon-custom']) ? ' '.$values['icon-custom'] : '').'">'.$values['icon-after'].'</span>';
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
|
|
|
|
2019-07-05 12:28:19 +02:00
|
|
|
if (!empty($values['validation'])) {
|
|
|
|
$result .= '
|
2019-07-30 16:51:33 +02:00
|
|
|
<span class="input-group-addon after" id="'.$pseudo_id.'_validation">
|
2019-07-05 12:28:19 +02:00
|
|
|
<span class="tip" title="'.tr('Validazione').'"><i class="fa fa-question-circle "></i></span>
|
|
|
|
</span>';
|
|
|
|
}
|
|
|
|
|
2017-08-04 16:28:16 +02:00
|
|
|
$result .= '
|
|
|
|
</div>';
|
|
|
|
|
|
|
|
unset($values['icon-before']);
|
|
|
|
unset($values['icon-after']);
|
|
|
|
unset($values['icon-custom']);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($values['help']) && !empty($values['show-help'])) {
|
|
|
|
$result .= '
|
|
|
|
<span class="help-block pull-left"><small>'.$values['help'].'</small></span>';
|
|
|
|
|
|
|
|
unset($values['help']);
|
|
|
|
unset($values['show-help']);
|
|
|
|
}
|
|
|
|
|
2019-07-05 12:28:19 +02:00
|
|
|
$values['data-parsley-errors-container'] = '#'.$pseudo_id.'-errors';
|
2017-08-04 16:28:16 +02:00
|
|
|
|
|
|
|
$result .= '
|
2017-08-29 16:34:02 +02:00
|
|
|
<div id="'.$values['id'].$rand.'-errors"></div>';
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2022-07-30 20:14:46 +02:00
|
|
|
$result .= '
|
|
|
|
</div>';
|
2017-08-04 16:28:16 +02:00
|
|
|
if (!empty($values['label'])) {
|
|
|
|
unset($values['label']);
|
|
|
|
}
|
|
|
|
|
2019-07-05 12:28:19 +02:00
|
|
|
if (!empty($values['validation'])) {
|
2019-07-18 18:33:56 +02:00
|
|
|
$values['valid'] = '1';
|
|
|
|
|
|
|
|
$value = explode('|', $values['validation']);
|
|
|
|
$name = $value[0];
|
2020-09-23 11:47:59 +02:00
|
|
|
$id_module = isset($value[1]) ? $value[1] : '$id_module$';
|
|
|
|
$id_record = isset($value[2]) ? $value[2] : '$id_record$';
|
2019-07-18 18:33:56 +02:00
|
|
|
|
2019-07-05 12:28:19 +02:00
|
|
|
$result .= '
|
|
|
|
<script>
|
|
|
|
var container = $("#'.$pseudo_id.'_validation");
|
2020-07-07 17:32:03 +02:00
|
|
|
|
2019-12-09 18:31:22 +01:00
|
|
|
container.closest(".input-group").find("input").on("change, blur", function(e){
|
2019-07-18 18:33:56 +02:00
|
|
|
var input = $(this);
|
|
|
|
var value = input.val();
|
2020-07-07 17:32:03 +02:00
|
|
|
|
2019-07-18 18:33:56 +02:00
|
|
|
var container = $("#'.$pseudo_id.'_validation");
|
|
|
|
var parent = container.closest(".input-group");
|
|
|
|
var message = container.find("span");
|
|
|
|
var icon = container.find("i");
|
2020-07-07 17:32:03 +02:00
|
|
|
|
2022-09-02 11:02:04 +02:00
|
|
|
var id_record = "'.$id_record.'";
|
2022-11-24 15:49:50 +01:00
|
|
|
var id_module = "'.$id_module.'";
|
2022-09-02 11:02:04 +02:00
|
|
|
|
2019-07-05 12:28:19 +02:00
|
|
|
icon.attr("class", "fa fa-spinner fa-spin");
|
2020-07-07 17:32:03 +02:00
|
|
|
|
2019-07-05 12:28:19 +02:00
|
|
|
$.ajax({
|
|
|
|
url: globals.rootdir + "/actions.php",
|
2019-07-18 18:33:56 +02:00
|
|
|
type: "post",
|
2019-07-05 12:28:19 +02:00
|
|
|
data: {
|
2022-11-24 15:49:50 +01:00
|
|
|
id_module: id_module,
|
2022-09-02 11:02:04 +02:00
|
|
|
id_record: id_record,
|
2019-07-18 18:33:56 +02:00
|
|
|
name: "'.$name.'",
|
2019-07-05 12:28:19 +02:00
|
|
|
value: value,
|
|
|
|
op: "validate",
|
|
|
|
},
|
|
|
|
success: function(data) {
|
|
|
|
data = JSON.parse(data);
|
2020-07-07 17:32:03 +02:00
|
|
|
|
2019-09-19 10:42:20 +02:00
|
|
|
if (value == "") {
|
2019-07-30 16:51:33 +02:00
|
|
|
parent.removeClass("has-success").removeClass("has-error");
|
|
|
|
icon.attr("class", "fa fa-question-circle");
|
|
|
|
message.tooltipster("content", "'.tr('Validazione').'");
|
2019-09-19 10:42:20 +02:00
|
|
|
} else {
|
2019-07-30 16:51:33 +02:00
|
|
|
if(data.result) {
|
|
|
|
icon.attr("class", "fa fa-check");
|
|
|
|
parent.addClass("has-success").removeClass("has-error");
|
|
|
|
} else {
|
|
|
|
icon.attr("class", "fa fa-close");
|
|
|
|
parent.addClass("has-error").removeClass("has-success");
|
|
|
|
}
|
2020-07-07 17:32:03 +02:00
|
|
|
|
2019-07-30 16:51:33 +02:00
|
|
|
message.tooltipster("content", data.message);
|
|
|
|
input.attr("valid", +(data.result));
|
2020-07-07 17:32:03 +02:00
|
|
|
|
2019-07-30 16:51:33 +02:00
|
|
|
if (data.fields) {
|
2019-09-19 17:46:17 +02:00
|
|
|
var fields = data.fields;
|
2020-07-07 17:32:03 +02:00
|
|
|
|
2019-09-19 17:46:17 +02:00
|
|
|
var form = input.closest("form");
|
2019-07-30 16:51:33 +02:00
|
|
|
Object.keys(fields).forEach(function(element) {
|
2019-09-19 17:46:17 +02:00
|
|
|
var single_input = form.find("[name=" + element + "]");
|
|
|
|
if (!single_input.val()) single_input.val(fields[element]).trigger("change");
|
2019-07-30 16:51:33 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-07-05 12:28:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
</script>';
|
|
|
|
}
|
|
|
|
|
2017-08-04 16:28:16 +02:00
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
2018-09-20 09:21:34 +02:00
|
|
|
protected function parser(&$values, &$extras, $string)
|
2017-08-04 16:28:16 +02:00
|
|
|
{
|
|
|
|
$result = $string;
|
|
|
|
|
2020-10-29 16:48:37 +01:00
|
|
|
if (string_starts_with($string, 'add|')) {
|
2018-09-20 09:21:34 +02:00
|
|
|
$result = $this->add($values, $extras, $string);
|
2017-08-04 16:28:16 +02:00
|
|
|
$values['icon-custom'] = 'no-padding';
|
2020-10-29 16:48:37 +01:00
|
|
|
} elseif (string_starts_with($string, 'choice|')) {
|
2018-09-20 09:21:34 +02:00
|
|
|
$result = $this->choice($values, $extras, $string);
|
2017-08-04 16:28:16 +02:00
|
|
|
$values['icon-custom'] = 'no-padding';
|
|
|
|
}
|
|
|
|
|
2020-10-29 16:48:37 +01:00
|
|
|
if (string_contains($string, '<button')) {
|
2020-09-03 13:54:43 +02:00
|
|
|
$values['icon-custom'] = 'no-padding';
|
|
|
|
}
|
|
|
|
|
2017-08-04 16:28:16 +02:00
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
2018-09-20 09:21:34 +02:00
|
|
|
protected function add(&$values, &$extras, $string)
|
2017-08-04 16:28:16 +02:00
|
|
|
{
|
|
|
|
$result = null;
|
|
|
|
|
|
|
|
$pieces = explode('|', $string);
|
|
|
|
|
2018-09-19 10:44:32 +02:00
|
|
|
$module_id = $pieces[1];
|
|
|
|
$module = Modules::get($module_id);
|
2018-03-29 00:26:23 +02:00
|
|
|
|
2018-06-23 15:41:32 +02:00
|
|
|
$get = !empty($pieces[2]) ? '&'.$pieces[2] : null;
|
|
|
|
$classes = !empty($pieces[3]) ? ' '.$pieces[3] : null;
|
2018-09-20 09:21:34 +02:00
|
|
|
$btn_extras = !empty($pieces[4]) ? ' '.$pieces[4] : null;
|
|
|
|
|
|
|
|
if (in_array('disabled', $extras)) {
|
|
|
|
$classes .= ' disabled';
|
|
|
|
$btn_extras .= ' disabled';
|
|
|
|
}
|
2018-03-29 00:26:23 +02:00
|
|
|
|
2018-08-11 15:37:38 +02:00
|
|
|
if (in_array($module->permission, ['r', 'rw'])) {
|
2017-08-04 16:28:16 +02:00
|
|
|
$result = '
|
2020-09-23 17:53:19 +02:00
|
|
|
<button type="button" class="btn'.$classes.'" '.$btn_extras.' onclick="openModal(\''.tr('Aggiungi').'\', \''.base_path().'/add.php?id_module='.$module->id.$get.'&select='.$values['id'].'&ajax=yes\')">
|
2017-08-04 16:28:16 +02:00
|
|
|
<i class="fa fa-plus"></i>
|
|
|
|
</button>';
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
2018-09-20 09:21:34 +02:00
|
|
|
protected function choice(&$values, &$extras, $string)
|
2017-08-04 16:28:16 +02:00
|
|
|
{
|
|
|
|
$result = null;
|
|
|
|
|
|
|
|
$pieces = explode('|', $string);
|
|
|
|
$type = $pieces[1];
|
2018-06-23 15:41:32 +02:00
|
|
|
$extra = !empty($pieces[3]) ? $pieces[3] : null;
|
2017-08-04 16:28:16 +02:00
|
|
|
|
|
|
|
if ($type == 'untprc') {
|
2018-02-21 17:47:43 +01:00
|
|
|
$choices = [
|
|
|
|
[
|
|
|
|
'id' => 'PRC',
|
|
|
|
'descrizione' => '%',
|
|
|
|
],
|
2019-02-14 16:17:31 +01:00
|
|
|
[
|
|
|
|
'id' => 'UNT',
|
2019-04-13 00:09:48 +02:00
|
|
|
'descrizione' => currency(),
|
2019-02-14 16:17:31 +01:00
|
|
|
],
|
2018-02-21 17:47:43 +01:00
|
|
|
];
|
|
|
|
} elseif ($type == 'email') {
|
|
|
|
$choices = [
|
|
|
|
[
|
|
|
|
'id' => 'a',
|
|
|
|
'descrizione' => tr('A').' ',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'id' => 'cc',
|
|
|
|
'descrizione' => tr('CC').' ',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'id' => 'bcc',
|
|
|
|
'descrizione' => tr('CCN'),
|
|
|
|
],
|
|
|
|
];
|
2020-07-07 17:15:47 +02:00
|
|
|
} elseif ($type == 'period') {
|
|
|
|
$choices = [
|
2020-07-07 18:07:56 +02:00
|
|
|
[
|
|
|
|
'id' => 'manual',
|
|
|
|
'descrizione' => tr('giorno/i (manuale)'),
|
|
|
|
],
|
2020-07-07 17:15:47 +02:00
|
|
|
[
|
2020-07-07 17:32:03 +02:00
|
|
|
'id' => 'days',
|
|
|
|
'descrizione' => tr('giorno/i'),
|
2020-07-07 17:15:47 +02:00
|
|
|
],
|
|
|
|
[
|
2020-07-07 17:32:03 +02:00
|
|
|
'id' => 'months',
|
|
|
|
'descrizione' => tr('mese/i'),
|
2020-07-07 17:15:47 +02:00
|
|
|
],
|
|
|
|
[
|
2020-07-07 17:32:03 +02:00
|
|
|
'id' => 'years',
|
|
|
|
'descrizione' => tr('anno/i'),
|
|
|
|
],
|
2020-07-07 17:15:47 +02:00
|
|
|
];
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
|
|
|
|
2018-02-21 17:47:43 +01:00
|
|
|
$value = (empty($pieces[2]) || !in_array($pieces[2], array_column($choices, 'id'))) ? $choices[0]['id'] : $pieces[2];
|
|
|
|
|
2020-10-30 17:15:33 +01:00
|
|
|
$result = '{[ "type": "select", "name": "tipo_'.prepareToField($values['name']).'", "id": "tipo_'.prepareToField($values['name']).'_'.rand(0, 99).'", "value": "'.prepareToField($value).'", "values": '.json_encode($choices).', "class": "no-search", "extra": "'.$extra.'" ]}';
|
2018-02-21 17:47:43 +01:00
|
|
|
|
|
|
|
$result = \HTMLBuilder\HTMLBuilder::replace($result);
|
|
|
|
|
2017-08-04 16:28:16 +02:00
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
}
|