Aggiunta Note interne

This commit is contained in:
Thomas Zilio 2019-07-26 11:57:59 +02:00
parent 30957f2363
commit 94e2049ad2
13 changed files with 305 additions and 48 deletions

View File

@ -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');

View File

@ -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'));

View File

@ -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) {
</li>';
}
// Tab per le note interne
if ($structure->permission != '-') {
echo '
<li class="bg-info">
<a data-toggle="tab" href="#tab_note" id="link-tab_note">'.tr('Note interne').'</a>
</li>';
}
$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) {
});
</script>';
if ($structure->permission != '-') {
echo '
<div id="tab_note" class="tab-pane">';
$note = $structure->notes($id_record);
if (!empty($note)) {
echo '
<div class="box box-warning direct-chat direct-chat-warning">
<div class="box-header with-border">
<h3 class="box-title">'.tr('Note interne').'</h3>
</div>
<div class="box-body">
<div class="direct-chat-messages" style="height: 50vh">';
foreach ($note as $nota) {
$utente = $nota->user;
$nome = $utente->anagrafica ? $utente->anagrafica->ragione_sociale.' ('.$utente->username.')' : $utente->username;
$photo = $utente->photo;
echo '
<div class="direct-chat-msg '.($utente->id == $user->id ? 'right' : '').'" id="nota_'.$nota->id.'">
<div class="direct-chat-info clearfix">
<span class="direct-chat-name pull-left">'.$nome.'</span>
<span class="direct-chat-timestamp pull-right">
'.timestampFormat($nota->created_at).'
</span>
</div>';
if ($photo) {
echo '
<img class="direct-chat-img" src="'.$photo.'">';
} else {
echo '
<i class="fa fa-user-circle-o direct-chat-img fa-3x" alt="'.tr('OpenSTAManager').'"></i>';
}
echo '
<div class="direct-chat-text">
<div class="pull-right">';
if (!empty($nota->notification_date)) {
echo '
<span class="label label-default tip" title="'.tr('Data di notifica').'" style="margin-right: 5px">
<i class="fa fa-bell"></i> '.dateFormat($nota->notification_date).'
</span>';
}
if ($user->is_admin || $utente->id == $user->id) {
echo '
<button type="button" class="btn btn-danger btn-xs ask" data-op="remove_nota" data-id_nota="'.$nota->id.'" data-msg="'.tr('Rimuovere questa nota?').'" data-backto="record-edit">
<i class="fa fa-trash-o"></i>
</button>';
}
echo '
</div>
'.$nota->content.'
</div>
</div>';
}
echo '
</div>
</div>
</div>';
} else {
echo '
<p>'.tr('Non sono presenti note interne').'</p>';
}
if ($structure->permission == 'rw') {
echo '
<form action="" method="post">
<input type="hidden" name="op" value="add_nota">
<input type="hidden" name="backto" value="record-edit">
{[ "type": "date", "label": "'.tr('Data di notifica').'", "name": "data_notifica" ]}
{[ "type": "ckeditor", "label": "'.tr('Nuova nota').'", "name": "contenuto", "required": 1]}
<!-- PULSANTI -->
<div class="row">
<div class="col-md-12 text-right">
<button type="sumbit" class="btn btn-primary">
<i class="fa fa-plus"></i> '.tr('Aggiungi').'
</button>
</div>
</div>
</form>';
}
echo '
</div>';
}
// Informazioni sulle operazioni
if (Auth::admin()) {
echo '
@ -349,6 +455,7 @@ if (empty($record) || !$has_access) {
<b>'.tr('Informazione:').'</b> '.tr('Nessun log disponibile per questa scheda').'.
</div>';
}
echo '
</div>';
}

View File

@ -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

View File

@ -54,7 +54,7 @@ if (!empty($utenti)) {
// Disabilitazione utente, se diverso da id_utente #1 (admin)
if ($utente['id'] == '1') {
echo '
<a title=""'.tr("Non è possibile disabilitare l'utente admin").'" class="text-muted tip">
<a title="'.tr("Non è possibile disabilitare l'utente admin").'" class="text-muted tip">
<i class="fa fa-2x fa-eye-slash"></i>
</a>';
} elseif ($utente['enabled'] == 1) {

View File

@ -24,55 +24,51 @@ $api = BASEURL.'/api/?token='.$token;
$module = Modules::get('Utenti e permessi');
echo '
<div class="box">
<div class="box-header">
<h3 class="box-title">'.tr('Account').'</h3>
<div class="box box-widget widget-user">
<div class="widget-user-header bg-yellow">
<h3 class="widget-user-username">'.$user['username'].'</h3>
<h5 class="widget-user-desc">'.$user['gruppo'].'</h5>
</div>
<div class="widget-user-image">';
<div class="box-body">';
// Cambio password e nome utente
echo '
<div class="row">
<div class="col-md-8">
<p>'.tr('Utente').': <b>'.$user['username'].'</b></p>
<p>'.tr('Gruppo').': <b>'.$user['gruppo'].'</b></p>';
if (!empty($anagrafica)) {
$user_photo = $user->photo;
if ($user_photo) {
echo '
<p>'.tr('Anagrafica associata').': <b>'.$anagrafica['ragione_sociale'].'</b></p>';
<img src="'.$user_photo.'" class="img-responsive" alt="'.$user['username'].'" />';
} else {
echo '
<i class="fa fa-user-circle-o fa-4x pull-left" alt="'.tr('OpenSTAManager').'"></i>';
}
echo '
</div>
<div class="col-md-4">
<a data-href="'.$module->fileurl('self.php').'?id_module='.$module->id.'&resource=photo" data-toggle="modal" ><img src="'.$user->photo.'" class="img-responsive img-thumbnail pull-right"></a>
</div>
</div><div class="clearfix">&nbsp;</div>';
if (!empty($module)) {
echo '
</div>
<div class="box-footer">
<div class="row">
<div class="col-md-6">
<a class="btn btn-warning btn-block tip" data-href="'.$module->fileurl('self.php').'?id_module='.$module->id.'&resource=password" data-toggle="modal" data-title="'.tr('Cambia password').'">
<i class="fa fa-unlock-alt"></i> '.tr('Cambia password').'
</a>
<div class="col-sm-4 border-right">
<div class="description-block">
<h5 class="description-header">'.tr('Anagrafica associata').'</h5>
<span class="description-text">'.(!empty($anagrafica) ? $anagrafica['ragione_sociale'] : tr('Nessuna')).'</span>
</div>
</div>
<div class="col-md-6">
<a class="btn btn-info btn-block tip" data-href="'.$module->fileurl('self.php').'?id_module='.$module->id.'&resource=photo" data-toggle="modal" data-title="'.tr('Cambia foto utente').'">
<i class="fa fa-picture-o"></i> '.tr('Cambia foto utente').'
</a>
<div class="col-sm-4 border-right">
<div class="description-block">
<a class="btn btn-info btn-block tip" data-href="'.$module->fileurl('self.php').'?id_module='.$module->id.'&resource=photo" data-toggle="modal" data-title="'.tr('Cambia foto utente').'">
<i class="fa fa-picture-o"></i> '.tr('Cambia foto utente').'
</a>
</div>
</div>
</div>';
}
echo '
<div class="col-sm-4 border-right">
<div class="description-block">
<a class="btn btn-warning btn-block tip" data-href="'.$module->fileurl('self.php').'?id_module='.$module->id.'&resource=password" data-toggle="modal" data-title="'.tr('Cambia password').'">
<i class="fa fa-unlock-alt"></i> '.tr('Cambia password').'
</a>
</div>
</div>
</div>
</div>
</div>';

View File

@ -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 = [];

61
src/Models/Note.php Normal file
View File

@ -0,0 +1,61 @@
<?php
namespace Models;
use Common\Model;
use Traits\NoteTrait;
class Note extends Model
{
protected $table = 'zz_notes';
/**
* Crea una nuova nota.
*
* @param User $user
* @param NoteTrait $structure
* @param int $id_record
* @param string $contenuto
* @param string $data_scadenza
*
* @return self
*/
public static function build(User $user, $structure, $id_record, $contenuto, $data_notifica = null)
{
$model = parent::build();
$model->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');
}
}

View File

@ -0,0 +1,27 @@
<?php
namespace Models;
use Common\Model;
class OperationLog extends Model
{
protected $table = 'zz_operations';
/* 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');
}
}

View File

@ -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',

View File

@ -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');

13
src/Traits/NoteTrait.php Normal file
View File

@ -0,0 +1,13 @@
<?php
namespace Traits;
use Models\Note;
trait NoteTrait
{
public function notes($id_record)
{
return $this->hasMany(Note::class, $this->note_identifier)->where('id_record', $id_record)->orderBy('created_at')->get();
}
}

View File

@ -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;