1
0
mirror of https://github.com/devcode-it/openstamanager.git synced 2024-12-22 13:26:38 +01:00

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,43 +268,51 @@ if (Modules::getPermission($permesso) == 'r' || Modules::getPermission($permesso
}
// Operazioni generiche per i campi personalizzati
if (post('op') != null && post('op') != 'delete') {
$customs = $dbo->fetchArray('SELECT `id`, `name` FROM `zz_fields` WHERE `id_module` = '.prepare($id_module));
$values = [];
foreach ($customs as $custom) {
if (isset($post[$custom['name']])) {
$values[$custom['id']] = $post[$custom['name']];
}
if (post('op') != null) {
$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);
// Inserimento iniziale
if (post('op') == 'add') {
foreach ($values as $key => $value) {
$dbo->insert('zz_field_record', [
if (!starts_with(post('op'), 'delete')) {
$values = [];
foreach ($customs as $custom) {
if (isset($post[$custom['name']])) {
$values[$custom['id']] = $post[$custom['name']];
}
}
// Inserimento iniziale
if (starts_with(post('op'), 'add')) {
foreach ($values as $key => $value) {
$dbo->insert('zz_field_record', [
'id_record' => $id_record,
'id_field' => $key,
'value' => $value,
]);
}
}
}
// Aggiornamento
elseif (post('op') == 'update') {
foreach ($values as $key => $value) {
$dbo->update('zz_field_record', [
// Aggiornamento
elseif (starts_with(post('op'), 'update')) {
foreach ($values as $key => $value) {
$dbo->update('zz_field_record', [
'value' => $value,
], [
'id_record' => $id_record,
'id_field' => $key,
]);
}
}
}
}
// Eliminazione
elseif (post('op') == 'delete') {
$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).')');
// Eliminazione
elseif (!empty($customs)) {
$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 '
<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 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>
<script>
$(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>';

View File

@ -105,19 +105,28 @@ if (empty($records)) {
// Campi personalizzati
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" )}
</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.'" )}
</div>
<script>
$(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>';

View File

@ -19,32 +19,28 @@ if (!empty($info['script'])) {
return;
} 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')) {
include_once $docroot.'/plugins/'.$info['directory'].'/custom/modutil.php';
} elseif (file_exists($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')) {
include $docroot.'/plugins/'.$info['directory'].'/custom/init.php';
} elseif (file_exists($docroot.'/plugins/'.$info['directory'].'/init.php')) {
include $docroot.'/plugins/'.$info['directory'].'/init.php';
}
// Esecuzione delle operazioni del modulo
if (file_exists($docroot.'/plugins/'.$info['directory'].'/custom/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';
}
// Esecuzione delle operazioni del plugin
include $docroot.'/actions.php';
if (empty($records)) {
echo '
<p>'.tr('Record non trovato').'.</p>';
} 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')) {
include $docroot.'/plugins/'.$info['directory'].'/custom/edit.php';
} 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')) {
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);
@ -73,7 +97,6 @@ if (!empty($info['script'])) {
</script>
<?php
}
}

View File

@ -6,31 +6,36 @@ $operazione = filter('op');
switch ($operazione) {
case 'addreferente':
$nome = filter('nome');
$mansione = filter('mansione');
$telefono = filter('telefono');
$email = filter('email');
$idsede = filter('idsede');
$dbo->insert('an_referenti', [
'idanagrafica' => $id_parent,
'nome' => $post['nome'],
'mansione' => $post['mansione'],
'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;
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->query($query);
$dbo->update('an_referenti', [
'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!');
break;
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!');

View File

@ -6,7 +6,7 @@ $operazione = filter('op');
switch ($operazione) {
case 'addsede':
$array = [
$dbo->insert('an_sedi', [
'idanagrafica' => $id_parent,
'nomesede' => $post['nomesede'],
'indirizzo' => $post['indirizzo'],
@ -18,9 +18,8 @@ switch ($operazione) {
'telefono' => $post['telefono'],
'email' => $post['email'],
'idzona' => $post['idzona'],
];
$dbo->insert('an_sedi', $array);
]);
$id_record = $dbo->lastInsertedID();
$_SESSION['infos'][] = tr('Aggiunta una nuova sede!');
@ -55,7 +54,7 @@ switch ($operazione) {
break;
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!');

View File

@ -21,19 +21,15 @@ class FieldManager implements ManagerInterface
$query = 'SELECT `zz_fields`.*'.(isset($options['id_record']) ? ', `zz_field_record`.`value`' : '').' FROM `zz_fields`';
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 ';
if (isset($options['id_plugin'])) {
$query .= ' `id_plugin` = '.prepare($options['id_plugin']);
if (!empty($options['id_plugin'])) {
$query .= '`id_plugin` = '.prepare($options['id_plugin']);
} else {
$query .= ' `id_module` = '.prepare($options['id_module']);
}
if (isset($options['id_record'])) {
$query .= ' AND `id_record` = '.prepare($options['id_record']);
$query .= '`id_module` = '.prepare($options['id_module']);
}
if (isset($options['place']) && $options['place'] == 'add') {
@ -52,49 +48,53 @@ class FieldManager implements ManagerInterface
// Spazio per evitare problemi con la sostituzione del tag
$result = ' ';
// Costruzione dei campi
foreach ($fields as $key => $field) {
if ($key % 3 == 0) {
$result .= '
if (!empty($fields)) {
$result .= '
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">'.tr('Campi aggiuntivi').'</h3>
</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">';
}
}
$field['value'] = isset($field['value']) ? $field['value'] : '';
$field['value'] = isset($field['value']) ? $field['value'] : '';
$replace = [
$replace = [
'value' => $field['value'],
'label' => $field['name'],
'name' => $field['html_name'],
];
foreach ($replace as $key => $value) {
$field['content'] = str_replace('|'.$key.'|', $value, $field['content']);
}
foreach ($replace as $key => $value) {
$field['content'] = str_replace('|'.$key.'|', $value, $field['content']);
}
$result .= '
$result .= '
<div class="col-xs-4">
'.$field['content'].'
</div>';
if (($key + 1) % 3 == 0) {
if (($key + 1) % 3 == 0) {
$result .= '
</div>';
}
}
if (($key + 1) % 3 != 0) {
$result .= '
</div>';
}
}
if (!empty($fields) && ($key + 1) % 3 != 0) {
$result .= '
</div>';
}
$result .= '
</div>
</div>';
}
return $result;
}