mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-02-16 19:40:44 +01:00
Aggiunta validazione AJAX dei campi
This commit is contained in:
parent
a8bad1e30a
commit
8d48d5c2e7
31
actions.php
31
actions.php
@ -10,7 +10,7 @@ $upload_dir = DOCROOT.'/'.Uploads::getDirectory($id_module, $id_plugin);
|
|||||||
|
|
||||||
$database->beginTransaction();
|
$database->beginTransaction();
|
||||||
|
|
||||||
// GESTIONE UPLOAD
|
// Upload allegati e rimozione
|
||||||
if (filter('op') == 'link_file' || filter('op') == 'unlink_file') {
|
if (filter('op') == 'link_file' || filter('op') == 'unlink_file') {
|
||||||
// Controllo sui permessi di scrittura per il modulo
|
// Controllo sui permessi di scrittura per il modulo
|
||||||
if (Modules::getPermission($id_module) != 'rw') {
|
if (Modules::getPermission($id_module) != 'rw') {
|
||||||
@ -65,11 +65,36 @@ if (filter('op') == 'link_file' || filter('op') == 'unlink_file') {
|
|||||||
|
|
||||||
redirect(ROOTDIR.'/editor.php?id_module='.$id_module.'&id_record='.$id_record.((!empty($options['id_plugin'])) ? '#tab_'.$options['id_plugin'] : ''));
|
redirect(ROOTDIR.'/editor.php?id_module='.$id_module.'&id_record='.$id_record.((!empty($options['id_plugin'])) ? '#tab_'.$options['id_plugin'] : ''));
|
||||||
}
|
}
|
||||||
} elseif (filter('op') == 'download_file') {
|
}
|
||||||
|
|
||||||
|
// Download allegati
|
||||||
|
elseif (filter('op') == 'download_file') {
|
||||||
$rs = $dbo->fetchArray('SELECT * FROM zz_files WHERE id_module='.prepare($id_module).' AND id='.prepare(filter('id')).' AND filename='.prepare(filter('filename')));
|
$rs = $dbo->fetchArray('SELECT * FROM zz_files WHERE id_module='.prepare($id_module).' AND id='.prepare(filter('id')).' AND filename='.prepare(filter('filename')));
|
||||||
|
|
||||||
download($upload_dir.'/'.$rs[0]['filename'], $rs[0]['original']);
|
download($upload_dir.'/'.$rs[0]['filename'], $rs[0]['original']);
|
||||||
} elseif (post('op') == 'send-email') {
|
}
|
||||||
|
|
||||||
|
// Validazione dati
|
||||||
|
elseif (filter('op') == 'validate') {
|
||||||
|
// Lettura informazioni di base
|
||||||
|
$init = $structure->filepath('init.php');
|
||||||
|
if (!empty($init)) {
|
||||||
|
include_once $init;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validazione del campo
|
||||||
|
$validation = $structure->filepath('validation.php');
|
||||||
|
if (!empty($validation)) {
|
||||||
|
include_once $validation;
|
||||||
|
}
|
||||||
|
|
||||||
|
echo json_encode($response);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Invio email
|
||||||
|
elseif (post('op') == 'send-email') {
|
||||||
$id_template = post('template');
|
$id_template = post('template');
|
||||||
|
|
||||||
// Inizializzazione
|
// Inizializzazione
|
||||||
|
@ -201,12 +201,12 @@ function translateTemplate()
|
|||||||
|
|
||||||
$template = ob_get_clean();
|
$template = ob_get_clean();
|
||||||
|
|
||||||
|
$template = \HTMLBuilder\HTMLBuilder::replace($template);
|
||||||
|
|
||||||
$template = str_replace('$id_module$', $id_module, $template);
|
$template = str_replace('$id_module$', $id_module, $template);
|
||||||
$template = str_replace('$id_plugin$', $id_plugin, $template);
|
$template = str_replace('$id_plugin$', $id_plugin, $template);
|
||||||
$template = str_replace('$id_record$', $id_record, $template);
|
$template = str_replace('$id_record$', $id_record, $template);
|
||||||
|
|
||||||
$template = \HTMLBuilder\HTMLBuilder::replace($template);
|
|
||||||
|
|
||||||
// Informazioni estese sulle azioni dell'utente
|
// Informazioni estese sulle azioni dell'utente
|
||||||
if (!empty(post('op')) && post('op') != 'send-email') {
|
if (!empty(post('op')) && post('op') != 'send-email') {
|
||||||
operationLog(post('op'));
|
operationLog(post('op'));
|
||||||
|
@ -48,11 +48,11 @@ echo '
|
|||||||
<div class="box-body">
|
<div class="box-body">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-4">
|
<div class="col-md-4">
|
||||||
{[ "type": "text", "label": "'.tr('Partita IVA').'", "maxlength": 13, "name": "piva", "class": "text-center alphanumeric-mask" ]}
|
{[ "type": "text", "label": "'.tr('Partita IVA').'", "maxlength": 13, "name": "piva", "class": "text-center alphanumeric-mask", "validation": "partita_iva"]}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-md-4">
|
<div class="col-md-4">
|
||||||
{[ "type": "text", "label": "'.tr('Codice fiscale').'", "maxlength": 16, "name": "codice_fiscale", "class": "text-center alphanumeric-mask" ]}
|
{[ "type": "text", "label": "'.tr('Codice fiscale').'", "maxlength": 16, "name": "codice_fiscale", "class": "text-center alphanumeric-mask", "validation": "codice_fiscale" ]}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-md-4">
|
<div class="col-md-4">
|
||||||
|
@ -43,7 +43,7 @@ if (!$cliente) {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-md-3">
|
<div class="col-md-3">
|
||||||
{[ "type": "text", "label": "<?php echo tr('Partita IVA'); ?>", "maxlength": 13, "name": "piva", "class": "text-center alphanumeric-mask text-uppercase", "value": "$piva$" ]}
|
{[ "type": "text", "label": "<?php echo tr('Partita IVA'); ?>", "maxlength": 13, "name": "piva", "class": "text-center alphanumeric-mask text-uppercase", "value": "$piva$", "validation": "partita_iva" ]}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-md-3">
|
<div class="col-md-3">
|
||||||
@ -62,7 +62,7 @@ if (!$cliente) {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-md-4">
|
<div class="col-md-4">
|
||||||
{[ "type": "text", "label": "<?php echo tr('Codice fiscale'); ?>", "maxlength": 16, "name": "codice_fiscale", "class": "text-center alphanumeric-mask text-uppercase", "value": "$codice_fiscale$" ]}
|
{[ "type": "text", "label": "<?php echo tr('Codice fiscale'); ?>", "maxlength": 16, "name": "codice_fiscale", "class": "text-center alphanumeric-mask text-uppercase", "value": "$codice_fiscale$", "validation": "codice_fiscale" ]}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
@ -90,7 +90,7 @@ if (!$cliente) {
|
|||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-2">
|
<div class="col-md-2">
|
||||||
{[ "type": "text", "label": "<?php echo tr('Codice anagrafica'); ?>", "name": "codice", "required": 1, "class": "text-center alphanumeric-mask", "value": "$codice$", "maxlength": 20 ]}
|
{[ "type": "text", "label": "<?php echo tr('Codice anagrafica'); ?>", "name": "codice", "required": 1, "class": "text-center alphanumeric-mask", "value": "$codice$", "maxlength": 20, "validation": "codice" ]}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-md-2">
|
<div class="col-md-2">
|
||||||
|
73
modules/anagrafiche/validation.php
Normal file
73
modules/anagrafiche/validation.php
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
include_once __DIR__.'/../../core.php';
|
||||||
|
use Modules\Anagrafiche\Anagrafica;
|
||||||
|
|
||||||
|
$name = get('name');
|
||||||
|
$value = get('value');
|
||||||
|
|
||||||
|
switch ($name) {
|
||||||
|
case 'codice':
|
||||||
|
$disponibile = Anagrafica::where([
|
||||||
|
['codice', $value],
|
||||||
|
['idanagrafica', '<>', $id_record],
|
||||||
|
])->count() == 0;
|
||||||
|
|
||||||
|
$message = $disponibile ? tr('Il codice è disponbile') : tr("Il codice è già utilizzato in un'altra anagrafica");
|
||||||
|
|
||||||
|
$response = [
|
||||||
|
'result' => $disponibile,
|
||||||
|
'message' => $message,
|
||||||
|
];
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'codice_fiscale':
|
||||||
|
$disponibile = Anagrafica::where([
|
||||||
|
['codice_fiscale', $value],
|
||||||
|
['idanagrafica', '<>', $id_record],
|
||||||
|
])->count() == 0;
|
||||||
|
|
||||||
|
$message = $disponibile ? tr('Il codice fiscale non è già inserito in una anagrafica') : tr("Il codice fiscale è già utilizzato in un'altra anagrafica");
|
||||||
|
|
||||||
|
// Validazione del Codice Fiscale, solo per anagrafiche Private e Aziende, ignoro controllo se codice fiscale e settato uguale alla p.iva
|
||||||
|
if (empty($anagrafica) || ($anagrafica->tipo != 'Ente pubblico' && $value != $anagrafica->partita_iva)) {
|
||||||
|
$check = Validate::isValidTaxCode($value);
|
||||||
|
if (empty($check)) {
|
||||||
|
$message .= '. '.tr('Attenzione: il codice fiscale _COD_ potrebbe non essere valido', [
|
||||||
|
'_COD_' => $value,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = [
|
||||||
|
'result' => $disponibile,
|
||||||
|
'message' => $message,
|
||||||
|
];
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'partita_iva':
|
||||||
|
$disponibile = Anagrafica::where([
|
||||||
|
['piva', $value],
|
||||||
|
['idanagrafica', '<>', $id_record],
|
||||||
|
])->count() == 0;
|
||||||
|
|
||||||
|
$message = $disponibile ? tr('La partita iva non è già inserita in una anagrafica') : tr('La partita iva è già utilizzata in un altro articolo');
|
||||||
|
|
||||||
|
$partita_iva = !empty($anagrafica) && is_numeric($value) ? $anagrafica->nazione->iso2.$value : $value;
|
||||||
|
|
||||||
|
$check = Validate::isValidVatNumber($partita_iva);
|
||||||
|
if (empty($check)) {
|
||||||
|
$message .= '. '.tr('Attenzione: la partita IVA _IVA_ potrebbe non essere valida', [
|
||||||
|
'_IVA_' => $partita_iva,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = [
|
||||||
|
'result' => $disponibile,
|
||||||
|
'message' => $message,
|
||||||
|
];
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
@ -30,7 +30,7 @@ if (!empty($record['immagine'])) {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-md-4">
|
<div class="col-md-4">
|
||||||
{[ "type": "text", "label": "<?php echo tr('Codice'); ?>", "name": "codice", "required": 1, "value": "$codice$" ]}
|
{[ "type": "text", "label": "<?php echo tr('Codice'); ?>", "name": "codice", "required": 1, "value": "$codice$", "validation": "codice" ]}
|
||||||
<br>
|
<br>
|
||||||
{[ "type": "select", "label": "<?php echo tr('Categoria'); ?>", "name": "categoria", "required": 1, "value": "$id_categoria$", "ajax-source": "categorie" ]}
|
{[ "type": "select", "label": "<?php echo tr('Categoria'); ?>", "name": "categoria", "required": 1, "value": "$id_categoria$", "ajax-source": "categorie" ]}
|
||||||
</div>
|
</div>
|
||||||
|
25
modules/articoli/validation.php
Normal file
25
modules/articoli/validation.php
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
include_once __DIR__.'/../../core.php';
|
||||||
|
|
||||||
|
use Modules\Articoli\Articolo;
|
||||||
|
|
||||||
|
$name = get('name');
|
||||||
|
$value = get('value');
|
||||||
|
|
||||||
|
switch ($name) {
|
||||||
|
case 'codice':
|
||||||
|
$disponibile = Articolo::where([
|
||||||
|
['codice', $value],
|
||||||
|
['id', '<>', $id_record],
|
||||||
|
])->count() == 0;
|
||||||
|
|
||||||
|
$message = $disponibile ? tr('Il codice è disponbile') : tr('Il codice è già utilizzato in un altro articolo');
|
||||||
|
|
||||||
|
$response = [
|
||||||
|
'result' => $disponibile,
|
||||||
|
'message' => $message,
|
||||||
|
];
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
@ -24,7 +24,7 @@ class HTMLWrapper implements WrapperInterface
|
|||||||
<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>';
|
<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>';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($values['icon-before']) || !empty($values['icon-after'])) {
|
if (!empty($values['icon-before']) || !empty($values['icon-after']) || !empty($values['validation'])) {
|
||||||
$result .= '
|
$result .= '
|
||||||
<div class="input-group">';
|
<div class="input-group">';
|
||||||
|
|
||||||
@ -39,14 +39,24 @@ class HTMLWrapper implements WrapperInterface
|
|||||||
|
|
||||||
public function after(&$values, &$extras)
|
public function after(&$values, &$extras)
|
||||||
{
|
{
|
||||||
|
$rand = rand(0, 99);
|
||||||
|
$pseudo_id = $values['id'].$rand;
|
||||||
|
|
||||||
$result = '';
|
$result = '';
|
||||||
|
|
||||||
if (!empty($values['icon-before']) || !empty($values['icon-after'])) {
|
if (!empty($values['icon-before']) || !empty($values['icon-after']) || !empty($values['validation'])) {
|
||||||
if (!empty($values['icon-after'])) {
|
if (!empty($values['icon-after'])) {
|
||||||
$result .= '
|
$result .= '
|
||||||
<span class="input-group-addon after'.(!empty($values['icon-custom']) ? ' '.$values['icon-custom'] : '').'">'.$values['icon-after'].'</span>';
|
<span class="input-group-addon after'.(!empty($values['icon-custom']) ? ' '.$values['icon-custom'] : '').'">'.$values['icon-after'].'</span>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!empty($values['validation'])) {
|
||||||
|
$result .= '
|
||||||
|
<span class="input-group-addon" id="'.$pseudo_id.'_validation">
|
||||||
|
<span class="tip" title="'.tr('Validazione').'"><i class="fa fa-question-circle "></i></span>
|
||||||
|
</span>';
|
||||||
|
}
|
||||||
|
|
||||||
$result .= '
|
$result .= '
|
||||||
</div>';
|
</div>';
|
||||||
|
|
||||||
@ -63,9 +73,7 @@ class HTMLWrapper implements WrapperInterface
|
|||||||
unset($values['show-help']);
|
unset($values['show-help']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$rand = rand(0, 99);
|
$values['data-parsley-errors-container'] = '#'.$pseudo_id.'-errors';
|
||||||
|
|
||||||
$values['data-parsley-errors-container'] = '#'.$values['id'].$rand.'-errors';
|
|
||||||
|
|
||||||
$result .= '
|
$result .= '
|
||||||
<div id="'.$values['id'].$rand.'-errors"></div>';
|
<div id="'.$values['id'].$rand.'-errors"></div>';
|
||||||
@ -76,6 +84,57 @@ class HTMLWrapper implements WrapperInterface
|
|||||||
unset($values['label']);
|
unset($values['label']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!empty($values['validation'])) {
|
||||||
|
$result .= '
|
||||||
|
<script>
|
||||||
|
var container = $("#'.$pseudo_id.'_validation");
|
||||||
|
|
||||||
|
container.closest(".input-group").find("input").on("change", function(){
|
||||||
|
value = $(this).val();
|
||||||
|
|
||||||
|
container = $("#'.$pseudo_id.'_validation");
|
||||||
|
parent = container.closest(".input-group");
|
||||||
|
message = container.find("span");
|
||||||
|
icon = container.find("i");
|
||||||
|
|
||||||
|
icon.attr("class", "fa fa-spinner fa-spin");
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: globals.rootdir + "/actions.php",
|
||||||
|
type: "get",
|
||||||
|
data: {
|
||||||
|
id_module: "$id_module$",
|
||||||
|
id_record: "$id_record$",
|
||||||
|
name: "'.$values['validation'].'",
|
||||||
|
value: value,
|
||||||
|
op: "validate",
|
||||||
|
},
|
||||||
|
success: function(data) {
|
||||||
|
data = JSON.parse(data);
|
||||||
|
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
|
||||||
|
message.tooltipster("content", data.message);
|
||||||
|
|
||||||
|
if (data.fields) {
|
||||||
|
fields = data.fields;
|
||||||
|
|
||||||
|
Object.keys(fields).forEach(function(element) {
|
||||||
|
$("[name=" + element + "]").val(fields[element]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>';
|
||||||
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user