diff --git a/actions.php b/actions.php index cc5af7de8..5dadf67e6 100644 --- a/actions.php +++ b/actions.php @@ -2,6 +2,8 @@ include_once __DIR__.'/core.php'; +use Models\Note; + if (empty($structure) || empty($structure['enabled'])) { die(tr('Accesso negato')); } @@ -93,6 +95,26 @@ elseif (filter('op') == 'validate') { return; } +// Aggiunta nota interna +elseif (filter('op') == 'add_nota') { + $contenuto = post('contenuto'); + $data_notifica = post('data_notifica') ?: null; + + $nota = Note::build($user, $structure, $id_record, $contenuto, $data_notifica); + + flash()->info(tr('Nota interna aggiunta correttamente!')); +} + +// Aggiunta nota interna +elseif (filter('op') == 'remove_nota') { + $id_nota = post('id_nota'); + $nota = Note::find($id_nota); + + $nota->delete(); + + flash()->info(tr('Nota interna aggiunta correttamente!')); +} + // Invio email elseif (post('op') == 'send-email') { $id_template = post('template'); diff --git a/core.php b/core.php index 19d36896b..c45c938a1 100644 --- a/core.php +++ b/core.php @@ -233,6 +233,7 @@ if (!API\Response::isAPIRequest()) { $id_record = filter('id_record'); $id_parent = filter('id_parent'); + $id_record = $id_record == $id_parent ? '' : $id_record; Modules::setCurrent(filter('id_module')); Plugins::setCurrent(filter('id_plugin')); diff --git a/editor.php b/editor.php index 1cb5c1e91..2450d85e1 100755 --- a/editor.php +++ b/editor.php @@ -4,19 +4,21 @@ include_once __DIR__.'/core.php'; use Carbon\Carbon; -if (empty($id_record) && !empty($id_module)) { +if (empty($id_record) && !empty($id_module) && empty($id_plugin)) { redirect(ROOTDIR.'/controller.php?id_module='.$id_module); -} elseif (empty($id_record) && empty($id_module)) { +} elseif (empty($id_record) && empty($id_module) && empty($id_plugin)) { redirect(ROOTDIR.'/index.php'); } include_once App::filepath('include|custom|', 'top.php'); -Util\Query::setSegments(false); -$query = Util\Query::getQuery($structure, [ - 'id' => $id_record, -]); -Util\Query::setSegments(true); +if (!empty($id_record)) { + Util\Query::setSegments(false); + $query = Util\Query::getQuery($structure, [ + 'id' => $id_record, + ]); + Util\Query::setSegments(true); +} $query = str_replace(['AND `deleted_at` IS NULL', '`deleted_at` IS NULL AND', '`deleted_at` IS NULL', 'AND deleted_at IS NULL', 'deleted_at IS NULL AND', 'deleted_at IS NULL'], '', $query); @@ -90,6 +92,14 @@ if (empty($record) || !$has_access) { '; } + // Tab per le note interne + if ($structure->permission != '-') { + echo ' +
  • + '.tr('Note interne').' +
  • '; + } + $plugins = $dbo->fetchArray('SELECT id, title FROM zz_plugins WHERE idmodule_to='.prepare($id_module)." AND position='tab' AND enabled = 1 ORDER BY zz_plugins.order DESC"); // Tab dei plugin @@ -272,6 +282,102 @@ if (empty($record) || !$has_access) { }); '; + if ($structure->permission != '-') { + echo ' +
    '; + + $note = $structure->notes($id_record); + if (!empty($note)) { + echo ' +
    +
    +

    '.tr('Note interne').'

    +
    + +
    +
    '; + + foreach ($note as $nota) { + $utente = $nota->user; + $nome = $utente->anagrafica ? $utente->anagrafica->ragione_sociale.' ('.$utente->username.')' : $utente->username; + $photo = $utente->photo; + + echo ' +
    +
    + '.$nome.' + + '.timestampFormat($nota->created_at).' + +
    '; + + if ($photo) { + echo ' + '; + } else { + echo ' + + '; + } + + echo ' +
    +
    '; + + if (!empty($nota->notification_date)) { + echo ' + + '.dateFormat($nota->notification_date).' + '; + } + + if ($user->is_admin || $utente->id == $user->id) { + echo ' + '; + } + + echo ' +
    + '.$nota->content.' +
    +
    '; + } + echo ' +
    +
    +
    '; + } else { + echo ' +

    '.tr('Non sono presenti note interne').'

    '; + } + + if ($structure->permission == 'rw') { + echo ' +
    + + + + {[ "type": "date", "label": "'.tr('Data di notifica').'", "name": "data_notifica" ]} + + {[ "type": "ckeditor", "label": "'.tr('Nuova nota').'", "name": "contenuto", "required": 1]} + + +
    +
    + +
    +
    +
    '; + } + + echo ' +
    '; + } + // Informazioni sulle operazioni if (Auth::admin()) { echo ' @@ -349,6 +455,7 @@ if (empty($record) || !$has_access) { '.tr('Informazione:').' '.tr('Nessun log disponibile per questa scheda').'. '; } + echo ' '; } diff --git a/modules/utenti/actions.php b/modules/utenti/actions.php index 32883802e..c47ba8135 100644 --- a/modules/utenti/actions.php +++ b/modules/utenti/actions.php @@ -53,7 +53,8 @@ switch (filter('op')) { $utente->password = $password; } } else { - $utente = User::build($username, $email, $password); + $gruppo = \Models\Group::find($id_record); + $utente = User::build($gruppo, $username, $email, $password); } // Foto diff --git a/modules/utenti/edit.php b/modules/utenti/edit.php index 6fe2e24df..4a5908766 100644 --- a/modules/utenti/edit.php +++ b/modules/utenti/edit.php @@ -54,7 +54,7 @@ if (!empty($utenti)) { // Disabilitazione utente, se diverso da id_utente #1 (admin) if ($utente['id'] == '1') { echo ' - + '; } elseif ($utente['enabled'] == 1) { diff --git a/modules/utenti/info.php b/modules/utenti/info.php index 143a369cb..ec7747415 100644 --- a/modules/utenti/info.php +++ b/modules/utenti/info.php @@ -24,55 +24,51 @@ $api = BASEURL.'/api/?token='.$token; $module = Modules::get('Utenti e permessi'); echo ' -
    -
    -

    '.tr('Account').'

    +
    +
    +

    '.$user['username'].'

    +
    '.$user['gruppo'].'
    + +
    '; -
    '; - -// Cambio password e nome utente -echo ' -
    -
    - -

    '.tr('Utente').': '.$user['username'].'

    -

    '.tr('Gruppo').': '.$user['gruppo'].'

    '; - -if (!empty($anagrafica)) { +$user_photo = $user->photo; +if ($user_photo) { echo ' -

    '.tr('Anagrafica associata').': '.$anagrafica['ragione_sociale'].'

    '; + '.$user['username'].''; +} else { + echo ' + '; } echo ' -
    - -
    - -
    - -
     
    '; - -if (!empty($module)) { - echo ' - +
    + + '; diff --git a/src/Models/Module.php b/src/Models/Module.php index 1b96e0ba7..0a2f108c5 100644 --- a/src/Models/Module.php +++ b/src/Models/Module.php @@ -6,6 +6,7 @@ use Auth; use Common\Model; use Illuminate\Database\Eloquent\Builder; use Traits\ManagerTrait; +use Traits\NoteTrait; use Traits\StoreTrait; use Traits\UploadTrait; @@ -14,10 +15,12 @@ class Module extends Model use ManagerTrait; use UploadTrait; use StoreTrait; + use NoteTrait; protected $table = 'zz_modules'; protected $main_folder = 'modules'; protected $upload_identifier = 'id_module'; + protected $note_identifier = 'id_module'; protected $variables = []; diff --git a/src/Models/Note.php b/src/Models/Note.php new file mode 100644 index 000000000..416d05812 --- /dev/null +++ b/src/Models/Note.php @@ -0,0 +1,61 @@ +user()->associate($user); + + if ($structure instanceof Module) { + $model->module()->associate($structure); + } elseif ($structure instanceof Plugin) { + $model->plugin()->associate($structure); + } + + $model->id_record = $id_record; + + $model->content = $contenuto; + $model->notification_date = $data_notifica; + + $model->save(); + + return $model; + } + + /* Relazioni Eloquent */ + + public function user() + { + return $this->belongsTo(User::class, 'id_utente'); + } + + public function plugin() + { + return $this->belongsTo(Plugin::class, 'id_plugin'); + } + + public function module() + { + return $this->belongsTo(Module::class, 'id_module'); + } +} diff --git a/src/Models/OperationLog.php b/src/Models/OperationLog.php new file mode 100644 index 000000000..d9bdb797e --- /dev/null +++ b/src/Models/OperationLog.php @@ -0,0 +1,27 @@ +belongsTo(User::class, 'id_utente'); + } + + public function plugin() + { + return $this->belongsTo(Plugin::class, 'id_plugin'); + } + + public function module() + { + return $this->belongsTo(Module::class, 'id_module'); + } +} diff --git a/src/Models/Plugin.php b/src/Models/Plugin.php index f565bf1d4..7315ff2e4 100644 --- a/src/Models/Plugin.php +++ b/src/Models/Plugin.php @@ -6,6 +6,7 @@ use App; use Common\Model; use Illuminate\Database\Eloquent\Builder; use Traits\ManagerTrait; +use Traits\NoteTrait; use Traits\StoreTrait; use Traits\UploadTrait; @@ -16,10 +17,12 @@ class Plugin extends Model use UploadTrait { getUploadDirectoryAttribute as protected defaultUploadDirectory; } + use NoteTrait; protected $table = 'zz_plugins'; protected $main_folder = 'plugins'; protected $upload_identifier = 'id_plugin'; + protected $note_identifier = 'id_plugin'; protected $appends = [ 'permission', diff --git a/src/Models/User.php b/src/Models/User.php index 1a952bee2..226ba6c62 100644 --- a/src/Models/User.php +++ b/src/Models/User.php @@ -40,6 +40,7 @@ class User extends Model /** * Crea un nuovo utente. * + * @param Group $gruppo * @param string $username * @param string $email * @param string $password @@ -56,6 +57,8 @@ class User extends Model $model->email = $email; $model->password = $password; + $model->enabled = 1; + $model->save(); return $model; @@ -172,6 +175,11 @@ class User extends Model return $this->hasMany(Log::class, 'id_utente'); } + public function notes() + { + return $this->hasMany(Note::class, 'id_utente'); + } + public function anagrafica() { return $this->belongsTo(Anagrafica::class, 'idanagrafica'); diff --git a/src/Traits/NoteTrait.php b/src/Traits/NoteTrait.php new file mode 100644 index 000000000..786df5fe6 --- /dev/null +++ b/src/Traits/NoteTrait.php @@ -0,0 +1,13 @@ +hasMany(Note::class, $this->note_identifier)->where('id_record', $id_record)->orderBy('created_at')->get(); + } +} diff --git a/update/2_4_11.sql b/update/2_4_11.sql index 3eff3fda8..9a777e188 100644 --- a/update/2_4_11.sql +++ b/update/2_4_11.sql @@ -188,3 +188,18 @@ INSERT INTO `zz_settings` (`id`, `nome`, `valore`, `tipo`, `editable`, `sezione` ALTER TABLE `co_scadenziario` ADD `data_concordata` DATE; UPDATE `zz_views` SET `query` = 'IF(pagato = da_pagare, ''#38CD4E'', IF(data_concordata IS NOT NULL AND data_concordata > NOW(), '' #CC9837'', IF(scadenza < NOW(), ''#CC4D37'', '''')))' WHERE `id_module` = (SELECT `id` FROM `zz_modules` WHERE `name` = 'Scadenzario') AND `name` = '_bg_'; + +-- Sistema di note interne +CREATE TABLE IF NOT EXISTS `zz_notes` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `id_module` int(11), + `id_plugin` int(11), + `id_record` int(11) NOT NULL, + `id_utente` int(11) NOT NULL, + `notification_date` DATE, + `content` TEXT, + PRIMARY KEY (`id`), + FOREIGN KEY (`id_module`) REFERENCES `zz_modules`(`id`) ON DELETE CASCADE, + FOREIGN KEY (`id_plugin`) REFERENCES `zz_plugins`(`id`) ON DELETE CASCADE, + FOREIGN KEY (`id_utente`) REFERENCES `zz_users`(`id`) ON DELETE CASCADE +) ENGINE=InnoDB;