Miglioramento gestione plugins e moduli

This commit is contained in:
Thomas Zilio 2018-07-18 16:12:25 +02:00
parent 08152f23d1
commit f04f2a99da
6 changed files with 132 additions and 169 deletions

View File

@ -4,18 +4,28 @@ include_once __DIR__.'/core.php';
// Lettura parametri iniziali
if (!empty($id_plugin)) {
$info = Plugins::get($id_plugin);
$element = Plugins::get($id_plugin);
$directory = '/plugins/'.$info['directory'];
$permesso = $info['idmodule_to'];
$id_module = $info['idmodule_to'];
$directory = '/plugins/'.$element['directory'];
$id_module = $element['idmodule_to'];
} else {
$info = Modules::get($id_module);
$element = Modules::get($id_module);
$directory = '/modules/'.$info['directory'];
$permesso = $id_module;
$directory = '/modules/'.$element['directory'];
}
if (empty($element) || empty($element['enabled'])) {
die(tr('Accesso negato'));
}
$php = App::filepath($directory.'|custom|', 'add.php');
$html = App::filepath($directory.'|custom|', 'add.html');
$element['add_file'] = !empty($php) ? $php : $html;
$php = App::filepath($directory.'|custom|', 'edit.php');
$html = App::filepath($directory.'|custom|', 'edit.html');
$element['edit_file'] = !empty($php) ? $php : $html;
$upload_dir = DOCROOT.'/'.Uploads::getDirectory($id_module, $id_plugin);
$dbo->query('START TRANSACTION');
@ -128,95 +138,93 @@ if (filter('op') == 'link_file' || filter('op') == 'unlink_file') {
}
}
if (Modules::getPermission($permesso) == 'r' || Modules::getPermission($permesso) == 'rw') {
// Inclusione di eventuale plugin personalizzato
if (!empty($info['script'])) {
include App::filepath('modules/'.$info['module_dir'].'/plugins|custom|', $info['script']);
// Inclusione di eventuale plugin personalizzato
if (!empty($element['script'])) {
include App::filepath('modules/'.$element['module_dir'].'/plugins|custom|', $element['script']);
$dbo->query('COMMIT');
$dbo->query('COMMIT');
return;
}
return;
}
// Caricamento helper modulo (verifico se ci sono helper personalizzati)
include_once App::filepath($directory.'|custom|', 'modutil.php');
// Caricamento helper modulo (verifico se ci sono helper personalizzati)
include_once App::filepath($directory.'|custom|', 'modutil.php');
// Lettura risultato query del modulo
include App::filepath($directory.'|custom|', 'init.php');
// Lettura risultato query del modulo
include App::filepath($directory.'|custom|', 'init.php');
// Retrocompatibilità
if (!isset($record) && isset($records[0])) {
$record = $records[0];
}
// Retrocompatibilità
if (!isset($record) && isset($records[0])) {
$record = $records[0];
}
// Registrazione del record
HTMLBuilder\HTMLBuilder::setRecord($record);
// Registrazione del record
HTMLBuilder\HTMLBuilder::setRecord($record);
if (Modules::getPermission($permesso) == 'rw') {
// Esecuzione delle operazioni di gruppo
$id_records = post('id_records');
$id_records = is_array($id_records) ? $id_records : explode(';', $id_records);
$id_records = array_filter($id_records, function ($var) {return !empty($var); });
$id_records = array_unique($id_records);
if (Modules::getPermission($id_module) == 'rw') {
// Esecuzione delle operazioni di gruppo
$id_records = post('id_records');
$id_records = is_array($id_records) ? $id_records : explode(';', $id_records);
$id_records = array_filter($id_records, function ($var) {return !empty($var); });
$id_records = array_unique($id_records);
$bulk = include App::filepath($directory.'|custom|', 'bulk.php');
$bulk = empty($bulk) ? [] : $bulk;
$bulk = include App::filepath($directory.'|custom|', 'bulk.php');
$bulk = empty($bulk) ? [] : $bulk;
if (in_array(post('op'), array_keys($bulk))) {
redirect(ROOTDIR.'/controller.php?id_module='.$id_module, 'js');
} else {
// Esecuzione delle operazioni del modulo
include App::filepath($directory.'|custom|', 'actions.php');
if (in_array(post('op'), array_keys($bulk))) {
redirect(ROOTDIR.'/controller.php?id_module='.$id_module, 'js');
} else {
// Esecuzione delle operazioni del modulo
include App::filepath($directory.'|custom|', 'actions.php');
// Operazioni generiche per i campi personalizzati
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);
// Operazioni generiche per i campi personalizzati
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);
if (!starts_with(post('op'), 'delete')) {
$values = [];
foreach ($customs as $custom) {
if (isset($post[$custom['name']])) {
$values[$custom['id']] = $post[$custom['name']];
}
}
$customs = $dbo->fetchArray($query);
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')) {
// Informazioni di log
Filter::set('get', 'id_record', $id_record);
foreach ($values as $key => $value) {
$dbo->insert('zz_field_record', [
'id_record' => $id_record,
'id_field' => $key,
'value' => $value,
]);
}
}
// Inserimento iniziale
if (starts_with(post('op'), 'add')) {
// Informazioni di log
Filter::set('get', 'id_record', $id_record);
foreach ($values as $key => $value) {
$dbo->insert('zz_field_record', [
'id_record' => $id_record,
'id_field' => $key,
'value' => $value,
]);
}
}
// Aggiornamento
elseif (starts_with(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 (!empty($customs)) {
$dbo->query('DELETE FROM `zz_field_record` WHERE `id_record` = '.prepare($id_record).' AND `id_field` IN ('.implode(array_column($customs, 'id')).')');
}
// 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')).')');
}
}
}

30
add.php
View File

@ -2,37 +2,21 @@
include_once __DIR__.'/core.php';
if (!empty($id_plugin)) {
$info = Plugins::get($id_plugin);
$directory = '/plugins/'.$info['directory'];
} else {
Permissions::check('rw');
$module = Modules::get($id_module);
$directory = '/modules/'.$module['directory'];
}
// Inclusione elementi fondamentali del modulo
include $docroot.'/actions.php';
// Controllo dei permessi
if (empty($id_plugin)) {
Permissions::check('rw');
}
// Caricamento template
echo '
<div id="form_'.$id_module.'-'.$id_plugin.'">
';
// Caricamento template
$file = !empty(get('edit')) ? 'edit' : 'add';
if (file_exists($docroot.$directory.'/custom/'.$file.'.php')) {
include $docroot.$directory.'/custom/'.$file.'.php';
} elseif (file_exists($docroot.$directory.'/custom/'.$file.'.html')) {
include $docroot.$directory.'/custom/'.$file.'.html';
} elseif (file_exists($docroot.$directory.'/'.$file.'.php')) {
include $docroot.$directory.'/'.$file.'.php';
} elseif (file_exists($docroot.$directory.'/'.$file.'.html')) {
include $docroot.$directory.'/'.$file.'.html';
}
include $element[$file.'_file'];
echo '
</div>';

View File

@ -10,16 +10,8 @@ if (!empty($id_record) && !empty($id_module)) {
include_once App::filepath('include|custom|', 'top.php');
// Lettura parametri iniziali del modulo
$module = Modules::get($id_module);
if (empty($module) || empty($module['enabled'])) {
die(tr('Accesso negato'));
}
$module_dir = $module['directory'];
include $docroot.'/actions.php';
// Inclusione gli elementi fondamentali
include_once $docroot.'/actions.php';
// Widget in alto
echo '{( "name": "widgets", "id_module": "'.$id_module.'", "position": "top", "place": "controller" )}';
@ -28,24 +20,23 @@ echo '{( "name": "widgets", "id_module": "'.$id_module.'", "position": "top", "p
echo '
<div class="nav-tabs-custom">
<ul class="nav nav-tabs pull-right" id="tabs" role="tablist">
<li class="pull-left active header">';
// Verifico se ho impostato un nome modulo personalizzato
$name = $module['title'];
echo '
<li class="pull-left active header">
<a data-toggle="tab" href="#tab_0">
<i class="'.$module['icon'].'"></i> '.$name;
<i class="'.$element['icon'].'"></i> '.$element['title'];
// Pulsante "Aggiungi" solo se il modulo è di tipo "table" e se esiste il template per la popup
if (file_exists($docroot.'/modules/'.$module_dir.'/add.php') && $module['permessi'] == 'rw') {
if (!empty($element['add_file']) && $element['permessi'] == 'rw') {
echo '
<button type="button" class="btn btn-primary" data-toggle="modal" data-title="'.tr('Aggiungi').'..." data-target="#bs-popup" data-href="add.php?id_module='.$id_module.'"><i class="fa fa-plus"></i></button>';
<button type="button" class="btn btn-primary" data-toggle="modal" data-title="'.tr('Aggiungi').'..." data-target="#bs-popup" data-href="add.php?id_module='.$id_module.'&id_plugin='.$id_plugin.'"><i class="fa fa-plus"></i></button>';
}
echo '
</a>
</li>';
$plugins = $dbo->fetchArray('SELECT id, title FROM zz_plugins WHERE idmodule_to='.prepare($id_module)." AND position='tab_main' AND enabled = 1");
// Tab dei plugin
foreach ($plugins as $plugin) {
echo '
<li>

View File

@ -10,17 +10,8 @@ if (empty($id_record) && !empty($id_module)) {
include_once App::filepath('include|custom|', 'top.php');
// Lettura parametri iniziali del modulo
$module = Modules::get($id_module);
if (empty($module) || empty($module['enabled'])) {
die(tr('Accesso negato'));
}
$module_dir = $module['directory'];
// Inclusione elementi fondamentali del modulo
include $docroot.'/actions.php';
// Inclusione gli elementi fondamentali
include_once $docroot.'/actions.php';
// Widget in alto
echo '{( "name": "widgets", "id_module": "'.$id_module.'", "id_record": "'.$id_record.'", "position": "top", "place": "editor" )}';
@ -28,6 +19,7 @@ echo '{( "name": "widgets", "id_module": "'.$id_module.'", "id_record": "'.$id_r
$advanced_sessions = setting('Attiva notifica di presenza utenti sul record');
if ($advanced_sessions) {
$dbo->query('DELETE FROM zz_semaphores WHERE id_utente='.prepare(Auth::user()['id_utente']).' AND posizione='.prepare($id_module.', '.$id_record));
$dbo->query('INSERT INTO zz_semaphores (id_utente, posizione, updated) VALUES ('.prepare(Auth::user()['id_utente']).', '.prepare($id_module.', '.$id_record).', NOW())');
echo '
@ -54,19 +46,16 @@ if (empty($record)) {
echo '
<div class="nav-tabs-custom">
<ul class="nav nav-tabs pull-right" id="tabs" role="tablist">
<li class="pull-left active header">';
// Verifico se ho impostato un nome modulo personalizzato
$name = $module['title'];
echo '
<li class="pull-left active header">
<a data-toggle="tab" href="#tab_0">
<i class="'.$module['icon'].'"></i> '.$name;
<i class="'.$element['icon'].'"></i> '.$element['title'];
// Pulsante "Aggiungi" solo se il modulo è di tipo "table" e se esiste il template per la popup
if (file_exists($docroot.'/modules/'.$module_dir.'/add.php') && $module['permessi'] == 'rw') {
if (!empty($element['add_file']) && $element['permessi'] == 'rw') {
echo '
<button type="button" class="btn btn-primary" data-toggle="modal" data-title="'.tr('Aggiungi').'..." data-target="#bs-popup" data-href="add.php?id_module='.$id_module.'"><i class="fa fa-plus"></i></button>';
<button type="button" class="btn btn-primary" data-toggle="modal" data-title="'.tr('Aggiungi').'..." data-target="#bs-popup" data-href="add.php?id_module='.$id_module.'&id_plugin='.$id_plugin.'"><i class="fa fa-plus"></i></button>';
}
echo '
</a>
</li>';
@ -173,16 +162,7 @@ if (empty($record)) {
<div id="module-edit">';
// Lettura template modulo (verifico se ci sono template personalizzati, altrimenti uso quello base)
if (file_exists($docroot.'/modules/'.$module_dir.'/custom/edit.php')) {
include $docroot.'/modules/'.$module_dir.'/custom/edit.php';
} elseif (file_exists($docroot.'/modules/'.$module_dir.'/custom/edit.html')) {
include $docroot.'/modules/'.$module_dir.'/custom/edit.html';
} elseif (file_exists($docroot.'/modules/'.$module_dir.'/edit.php')) {
include $docroot.'/modules/'.$module_dir.'/edit.php';
} elseif (file_exists($docroot.'/modules/'.$module_dir.'/edit.html')) {
include $docroot.'/modules/'.$module_dir.'/edit.html';
}
include $element['edit_file'];
echo '
</div>
@ -314,7 +294,7 @@ echo '
<script>';
// Se l'utente ha i permessi in sola lettura per il modulo, converto tutti i campi di testo in span
$read_only = Modules::getPermission($id_module) == 'r';
$read_only = $element['permessi'] == 'r';
if ($read_only || !empty($block_edit)) {
$not = $read_only ? '' : '.not(".unblockable")';

View File

@ -2,10 +2,22 @@
include_once __DIR__.'/../core.php';
// Lettura parametri iniziali del modulo
// Lettura parametri iniziali
if (!empty($id_plugin)) {
$element = Plugins::get($id_plugin);
$directory = '/plugins/'.$element['directory'];
} else {
$element = Modules::get($id_module);
$directory = '/modules/'.$element['directory'];
}
$php = App::filepath($directory.'|custom|', 'edit.php');
$html = App::filepath($directory.'|custom|', 'edit.html');
$element['edit_file'] = !empty($php) ? $php : $html;
if (!empty($id_plugin)) {
// Inclusione di eventuale plugin personalizzato
if (!empty($element['script'])) {
include App::filepath('modules/'.$element['module_dir'].'/plugins|custom|', $element['script']);
@ -18,23 +30,18 @@ if (!empty($id_plugin)) {
<span class="'.(!empty($element['help']) ? ' tip' : '').'"'.(!empty($element['help']) ? ' title="'.prepareToField($element['help']).'" data-position="bottom"' : '').' >
'.$element['title'].(!empty($element['help']) ? ' <i class="fa fa-question-circle-o"></i>' : '').'</span>';
if (file_exists($docroot.'/plugins/'.$element['directory'].'/add.php')) {
if (!empty(Plugins::filepath($id_plugin, 'add.php'))) {
echo '
<button type="button" class="btn btn-primary" data-toggle="modal" data-title="'.tr('Aggiungi').'..." data-target="#bs-popup" data-href="add.php?id_module='.$id_module.'&id_plugin='.$id_plugin.'&id_parent='.$id_record.'"><i class="fa fa-plus"></i></button>';
}
echo '
</h4>';
$directory = '/plugins/'.$element['directory'];
} else {
$element = Modules::get($id_module);
$directory = '/modules/'.$element['directory'];
}
$total = App::readQuery($element);
$module_options = (!empty($element['options2'])) ? $element['options2'] : $element['options'];
$type = $element['option'];
// Caricamento helper modulo (verifico se ci sono helper personalizzati)
include_once App::filepath($directory.'|custom|', 'modutil.php');
@ -48,8 +55,8 @@ include App::filepath($directory.'|custom|', 'controller_before.php');
/*
* Datatables con record
*/
if (!empty($module_options) && $module_options != 'menu' && $module_options != 'custom') {
if (count(Modules::getSegments($id_module)) > 1) {
if (!empty($type) && $type != 'menu' && $type != 'custom') {
if (empty($id_plugin) && count(Modules::getSegments($id_module)) > 1) {
echo '
<div class="row">
<div class="col-md-4 pull-right">
@ -210,17 +217,8 @@ if (!empty($module_options) && $module_options != 'menu' && $module_options != '
/*
* Inclusione modulo personalizzato
*/
elseif ($module_options == 'custom') {
// Lettura template modulo (verifico se ci sono template personalizzati, altrimenti uso quello base)
if (file_exists($docroot.$directory.'/custom/edit.php')) {
include $docroot.$directory.'/custom/edit.php';
} elseif (file_exists($docroot.$directory.'/custom/edit.html')) {
include $docroot.$directory.'/custom/edit.html';
} elseif (file_exists($docroot.$directory.'/edit.php')) {
include $docroot.$directory.'/edit.php';
} elseif (file_exists($docroot.$directory.'/edit.html')) {
include $docroot.$directory.'/edit.html';
}
elseif ($type == 'custom') {
include $element['edit_file'];
}
// Caricamento file aggiuntivo su elenco record

View File

@ -32,6 +32,8 @@ class Plugins
$result['option'] = empty($result['options2']) ? $result['options'] : $result['options2'];
$result['permessi'] = Modules::getPermission($result['idmodule_to']);
$plugins[$result['id']] = $result;
$plugins[$result['name']] = $result['id'];
}