Completo supporto ai plugin (campi personalizzati)

This commit is contained in:
Thomas Zilio 2018-02-15 17:30:42 +01:00
parent 70d574249a
commit 58bbe8f417
7 changed files with 138 additions and 85 deletions

View File

@ -268,9 +268,16 @@ if (Modules::getPermission($permesso) == 'r' || Modules::getPermission($permesso
} }
// Operazioni generiche per i campi personalizzati // Operazioni generiche per i campi personalizzati
if (post('op') != null && post('op') != 'delete') { if (post('op') != null) {
$customs = $dbo->fetchArray('SELECT `id`, `name` FROM `zz_fields` WHERE `id_module` = '.prepare($id_module)); $query = 'SELECT `id`, `name` FROM `zz_fields` WHERE ';
if (!empty($id_plugin)) {
$query .= '`id_plugin` = '.prepare($id_plugin);
} else {
$query .= '`id_module` = '.prepare($id_module);
}
$customs = $dbo->fetchArray($query);
if (!starts_with(post('op'), 'delete')) {
$values = []; $values = [];
foreach ($customs as $custom) { foreach ($customs as $custom) {
if (isset($post[$custom['name']])) { if (isset($post[$custom['name']])) {
@ -279,7 +286,7 @@ if (Modules::getPermission($permesso) == 'r' || Modules::getPermission($permesso
} }
// Inserimento iniziale // Inserimento iniziale
if (post('op') == 'add') { if (starts_with(post('op'), 'add')) {
foreach ($values as $key => $value) { foreach ($values as $key => $value) {
$dbo->insert('zz_field_record', [ $dbo->insert('zz_field_record', [
'id_record' => $id_record, 'id_record' => $id_record,
@ -290,7 +297,7 @@ if (Modules::getPermission($permesso) == 'r' || Modules::getPermission($permesso
} }
// Aggiornamento // Aggiornamento
elseif (post('op') == 'update') { elseif (starts_with(post('op'), 'update')) {
foreach ($values as $key => $value) { foreach ($values as $key => $value) {
$dbo->update('zz_field_record', [ $dbo->update('zz_field_record', [
'value' => $value, 'value' => $value,
@ -303,8 +310,9 @@ if (Modules::getPermission($permesso) == 'r' || Modules::getPermission($permesso
} }
// Eliminazione // Eliminazione
elseif (post('op') == 'delete') { elseif (!empty($customs)) {
$dbo->query('DELETE FROM `zz_field_record` WHERE `id_record` = '.prepare($id_record).' AND `id_field` IN (SELECT `id` FROM `zz_fields` WHERE `id_module` = '.prepare($id_module).')'); $dbo->query('DELETE FROM `zz_field_record` WHERE `id_record` = '.prepare($id_record).' AND `id_field` IN ('.implode(array_column($customs, 'id')).')');
}
} }
} }
} }

17
add.php
View File

@ -38,18 +38,27 @@ echo '
echo ' echo '
<div class="hide" id="custom_fields_top-add"> <div class="hide" id="custom_fields_top-add">
{( "name": "custom_fields", "id_module": "'.$id_module.'", "position": "top", "place": "add" )} {( "name": "custom_fields", "id_module": "'.$id_module.'", "id_plugin": "'.$id_plugin.'", "position": "top", "place": "add" )}
</div> </div>
<div class="hide" id="custom_fields_bottom-add"> <div class="hide" id="custom_fields_bottom-add">
{( "name": "custom_fields", "id_module": "'.$id_module.'", "position": "bottom", "place": "add" )} {( "name": "custom_fields", "id_module": "'.$id_module.'", "id_plugin": "'.$id_plugin.'", "position": "bottom", "place": "add" )}
</div> </div>
<script> <script>
$(document).ready(function(){ $(document).ready(function(){
$("#form_'.$id_module.'-'.$id_plugin.' form:first").prepend($("#custom_fields_top-add").html()); var form = $("#custom_fields_top-add").parent().find("form").first();
$("#form_'.$id_module.'-'.$id_plugin.' form:first .panel").last().after($("#custom_fields_bottom-add").html()); // Campi a inizio form
form.prepend($("#custom_fields_top-add").html());
// Campi a fine form
var last = form.find(".panel").last();
if (!last.length) {
last = form.find(".row").eq(-2);
}
last.after($("#custom_fields_bottom-add").html());
}); });
</script>'; </script>';

View File

@ -105,19 +105,28 @@ if (empty($records)) {
// Campi personalizzati // Campi personalizzati
echo ' echo '
<div class="hide" id="custom_fields_top"> <div class="hide" id="custom_fields_top-edit">
{( "name": "custom_fields", "id_module": "'.$id_module.'", "id_record": "'.$id_record.'", "position": "top" )} {( "name": "custom_fields", "id_module": "'.$id_module.'", "id_record": "'.$id_record.'", "position": "top" )}
</div> </div>
<div class="hide" id="custom_fields_bottom"> <div class="hide" id="custom_fields_bottom-edit">
{( "name": "custom_fields", "id_module": "'.$id_module.'", "id_record": "'.$id_record.'" )} {( "name": "custom_fields", "id_module": "'.$id_module.'", "id_record": "'.$id_record.'" )}
</div> </div>
<script> <script>
$(document).ready(function(){ $(document).ready(function(){
$("#tab_0 form:first").prepend($("#custom_fields_top").html()); var form = $("#custom_fields_top-edit").parent().find("form").first();
$("#tab_0 form:first .panel").last().after($("#custom_fields_bottom").html()); // Campi a inizio form
form.prepend($("#custom_fields_top-edit").html());
// Campi a fine form
var last = form.find(".panel").last();
if (!last.length) {
last = form.find(".row").eq(-2);
}
last.after($("#custom_fields_bottom-edit").html());
}); });
</script>'; </script>';

View File

@ -19,32 +19,28 @@ if (!empty($info['script'])) {
return; return;
} else { } else {
// Caricamento helper modulo (verifico se ci sono helper personalizzati) // Caricamento helper plugin (verifico se ci sono helper personalizzati)
if (file_exists($docroot.'/plugins/'.$info['directory'].'/custom/modutil.php')) { if (file_exists($docroot.'/plugins/'.$info['directory'].'/custom/modutil.php')) {
include_once $docroot.'/plugins/'.$info['directory'].'/custom/modutil.php'; include_once $docroot.'/plugins/'.$info['directory'].'/custom/modutil.php';
} elseif (file_exists($docroot.'/plugins/'.$info['directory'].'/modutil.php')) { } elseif (file_exists($docroot.'/plugins/'.$info['directory'].'/modutil.php')) {
include_once $docroot.'/plugins/'.$info['directory'].'/modutil.php'; include_once $docroot.'/plugins/'.$info['directory'].'/modutil.php';
} }
// Lettura risultato query del modulo // Lettura risultato query del plugin
if (file_exists($docroot.'/plugins/'.$info['directory'].'/custom/init.php')) { if (file_exists($docroot.'/plugins/'.$info['directory'].'/custom/init.php')) {
include $docroot.'/plugins/'.$info['directory'].'/custom/init.php'; include $docroot.'/plugins/'.$info['directory'].'/custom/init.php';
} elseif (file_exists($docroot.'/plugins/'.$info['directory'].'/init.php')) { } elseif (file_exists($docroot.'/plugins/'.$info['directory'].'/init.php')) {
include $docroot.'/plugins/'.$info['directory'].'/init.php'; include $docroot.'/plugins/'.$info['directory'].'/init.php';
} }
// Esecuzione delle operazioni del modulo // Esecuzione delle operazioni del plugin
if (file_exists($docroot.'/plugins/'.$info['directory'].'/custom/actions.php')) { include $docroot.'/actions.php';
include $docroot.'/plugins/'.$info['directory'].'/custom/actions.php';
} elseif (file_exists($docroot.'/plugins/'.$info['directory'].'/actions.php')) {
include $docroot.'/plugins/'.$info['directory'].'/actions.php';
}
if (empty($records)) { if (empty($records)) {
echo ' echo '
<p>'.tr('Record non trovato').'.</p>'; <p>'.tr('Record non trovato').'.</p>';
} else { } else {
// Lettura template modulo (verifico se ci sono template personalizzati, altrimenti uso quello base) // Lettura template plugin (verifico se ci sono template personalizzati, altrimenti uso quello base)
if (file_exists($docroot.'/plugins/'.$info['directory'].'/custom/edit.php')) { if (file_exists($docroot.'/plugins/'.$info['directory'].'/custom/edit.php')) {
include $docroot.'/plugins/'.$info['directory'].'/custom/edit.php'; include $docroot.'/plugins/'.$info['directory'].'/custom/edit.php';
} elseif (file_exists($docroot.'/plugins/'.$info['directory'].'/custom/edit.html')) { } elseif (file_exists($docroot.'/plugins/'.$info['directory'].'/custom/edit.html')) {
@ -54,6 +50,34 @@ if (!empty($info['script'])) {
} elseif (file_exists($docroot.'/plugins/'.$info['directory'].'/edit.html')) { } elseif (file_exists($docroot.'/plugins/'.$info['directory'].'/edit.html')) {
include $docroot.'/plugins/'.$info['directory'].'/edit.html'; include $docroot.'/plugins/'.$info['directory'].'/edit.html';
} }
// Campi personalizzati
echo '
<div class="hide" id="custom_fields_top-plugin">
{( "name": "custom_fields", "id_plugin": "'.$id_plugin.'", "id_record": "'.$id_record.'", "position": "top" )}
</div>
<div class="hide" id="custom_fields_bottom-plugin">
{( "name": "custom_fields", "id_plugin": "'.$id_plugin.'", "id_record": "'.$id_record.'" )}
</div>
<script>
$(document).ready(function(){
var form = $("#custom_fields_top-plugin").parent().find("form").first();
// Campi a inizio form
form.prepend($("#custom_fields_top-plugin").html());
// Campi a fine form
var last = form.find(".panel").last();
if (!last.length) {
last = form.find(".row").eq(-2);
}
last.after($("#custom_fields_bottom-plugin").html());
});
</script>';
} }
redirectOperation($id_module, $id_parent); redirectOperation($id_module, $id_parent);
@ -73,7 +97,6 @@ if (!empty($info['script'])) {
</script> </script>
<?php <?php
} }
} }

View File

@ -6,31 +6,36 @@ $operazione = filter('op');
switch ($operazione) { switch ($operazione) {
case 'addreferente': case 'addreferente':
$nome = filter('nome'); $dbo->insert('an_referenti', [
$mansione = filter('mansione'); 'idanagrafica' => $id_parent,
$telefono = filter('telefono'); 'nome' => $post['nome'],
$email = filter('email'); 'mansione' => $post['mansione'],
$idsede = filter('idsede'); 'telefono' => $post['telefono'],
'email' => $post['email'],
'idsede' => $post['idsede'],
]);
$id_record = $dbo->lastInsertedID();
if (isset($nome) && isset($idsede)) {
$query = 'INSERT INTO `an_referenti` (`nome`, `mansione`, `telefono`, `email`, `idanagrafica`, `idsede`) VALUES ('.prepare($nome).', '.prepare($mansione).', '.prepare($telefono).', '.prepare($email).', '.prepare($id_parent).', '.prepare($idsede).')';
$dbo->query($query);
$_SESSION['infos'][] = tr('Aggiunto nuovo referente!'); $_SESSION['infos'][] = tr('Aggiunto nuovo referente!');
}
break; break;
case 'updatereferente': case 'updatereferente':
$query = 'UPDATE `an_referenti` SET `nome`='.prepare($post['nome']).', `mansione`='.prepare($post['mansione']).', `telefono`='.prepare($post['telefono']).', `email`='.prepare($post['email']).', `idsede`='.prepare($post['idsede']).' WHERE `id`='.prepare($id_record); $dbo->update('an_referenti', [
$dbo->query($query); 'idanagrafica' => $id_parent,
'nome' => $post['nome'],
'mansione' => $post['mansione'],
'telefono' => $post['telefono'],
'email' => $post['email'],
'idsede' => $post['idsede'],
], ['id' => $id_record]);
$_SESSION['infos'][] = tr('Salvataggio completato!'); $_SESSION['infos'][] = tr('Salvataggio completato!');
break; break;
case 'deletereferente': case 'deletereferente':
$dbo->query("DELETE FROM `an_referenti` WHERE `id`=".prepare($id_record)); $dbo->query('DELETE FROM `an_referenti` WHERE `id`='.prepare($id_record));
$_SESSION['infos'][] = tr('Referente eliminato!'); $_SESSION['infos'][] = tr('Referente eliminato!');

View File

@ -6,7 +6,7 @@ $operazione = filter('op');
switch ($operazione) { switch ($operazione) {
case 'addsede': case 'addsede':
$array = [ $dbo->insert('an_sedi', [
'idanagrafica' => $id_parent, 'idanagrafica' => $id_parent,
'nomesede' => $post['nomesede'], 'nomesede' => $post['nomesede'],
'indirizzo' => $post['indirizzo'], 'indirizzo' => $post['indirizzo'],
@ -18,9 +18,8 @@ switch ($operazione) {
'telefono' => $post['telefono'], 'telefono' => $post['telefono'],
'email' => $post['email'], 'email' => $post['email'],
'idzona' => $post['idzona'], 'idzona' => $post['idzona'],
]; ]);
$id_record = $dbo->lastInsertedID();
$dbo->insert('an_sedi', $array);
$_SESSION['infos'][] = tr('Aggiunta una nuova sede!'); $_SESSION['infos'][] = tr('Aggiunta una nuova sede!');
@ -55,7 +54,7 @@ switch ($operazione) {
break; break;
case 'deletesede': case 'deletesede':
$dbo->query("DELETE FROM `an_sedi` WHERE `id`=".prepare($id_record)); $dbo->query('DELETE FROM `an_sedi` WHERE `id`='.prepare($id_record));
$_SESSION['infos'][] = tr('Sede eliminata!'); $_SESSION['infos'][] = tr('Sede eliminata!');

View File

@ -21,21 +21,17 @@ class FieldManager implements ManagerInterface
$query = 'SELECT `zz_fields`.*'.(isset($options['id_record']) ? ', `zz_field_record`.`value`' : '').' FROM `zz_fields`'; $query = 'SELECT `zz_fields`.*'.(isset($options['id_record']) ? ', `zz_field_record`.`value`' : '').' FROM `zz_fields`';
if (isset($options['id_record'])) { if (isset($options['id_record'])) {
$query .= ' LEFT JOIN `zz_field_record` ON `zz_fields`.`id` = `zz_field_record`.`id_field`'; $query .= ' LEFT JOIN `zz_field_record` ON `zz_fields`.`id` = `zz_field_record`.`id_field` AND `zz_field_record`.`id_record` = '.prepare($options['id_record']);
} }
$query .= ' WHERE '; $query .= ' WHERE ';
if (isset($options['id_plugin'])) { if (!empty($options['id_plugin'])) {
$query .= '`id_plugin` = '.prepare($options['id_plugin']); $query .= '`id_plugin` = '.prepare($options['id_plugin']);
} else { } else {
$query .= '`id_module` = '.prepare($options['id_module']); $query .= '`id_module` = '.prepare($options['id_module']);
} }
if (isset($options['id_record'])) {
$query .= ' AND `id_record` = '.prepare($options['id_record']);
}
if (isset($options['place']) && $options['place'] == 'add') { if (isset($options['place']) && $options['place'] == 'add') {
$query .= ' AND `on_add` = 1'; $query .= ' AND `on_add` = 1';
} }
@ -52,15 +48,18 @@ class FieldManager implements ManagerInterface
// Spazio per evitare problemi con la sostituzione del tag // Spazio per evitare problemi con la sostituzione del tag
$result = ' '; $result = ' ';
// Costruzione dei campi if (!empty($fields)) {
foreach ($fields as $key => $field) {
if ($key % 3 == 0) {
$result .= ' $result .= '
<div class="panel panel-primary"> <div class="panel panel-primary">
<div class="panel-heading"> <div class="panel-heading">
<h3 class="panel-title">'.tr('Campi aggiuntivi').'</h3> <h3 class="panel-title">'.tr('Campi aggiuntivi').'</h3>
</div> </div>
<div class="panel-body"> <div class="panel-body">';
// Costruzione dei campi
foreach ($fields as $key => $field) {
if ($key % 3 == 0) {
$result .= '
<div class="row">'; <div class="row">';
} }
@ -87,7 +86,7 @@ class FieldManager implements ManagerInterface
} }
} }
if (!empty($fields) && ($key + 1) % 3 != 0) { if (($key + 1) % 3 != 0) {
$result .= ' $result .= '
</div>'; </div>';
} }
@ -95,6 +94,7 @@ class FieldManager implements ManagerInterface
$result .= ' $result .= '
</div> </div>
</div>'; </div>';
}
return $result; return $result;
} }