CREATE TABLE `zz_plugins` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL,
  `idmodule_from` int(11) NOT NULL,
  `idmodule_to` int(11) NOT NULL,
  `position` varchar(50) NOT NULL,
  `script` varchar(255) NOT NULL,
  `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `updated_by` int(11) NOT NULL,
  `created_by` int(11) NOT NULL,
  `path` text NOT NULL,
    PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;


CREATE TABLE `zz_log_anagrafiche` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `idutente` int(11) NOT NULL,
  `idanagrafica` int(11) NOT NULL,
  `username` varchar(50) NOT NULL,
  `descrizione` text NOT NULL,
  `data_log` datetime NOT NULL,
   PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `zz_log_magazzino` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `idutente` int(11) NOT NULL,
  `idarticolo` int(11) NOT NULL,
  `username` varchar(50) NOT NULL,
  `descrizione` text NOT NULL,
  `data_log` datetime NOT NULL,
   PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `zz_log_documenti` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `idutente` int(11) NOT NULL,
  `iddocumento` int(11) NOT NULL,
  `username` varchar(50) NOT NULL,
  `descrizione` text NOT NULL,
  `data_log` datetime NOT NULL,
   PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `zz_log_contratti` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `idutente` int(11) NOT NULL,
  `idcontratto` int(11) NOT NULL,
  `username` varchar(50) NOT NULL,
  `descrizione` text NOT NULL,
  `data_log` datetime NOT NULL,
   PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `zz_log_installazioni` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `idutente` int(11) NOT NULL,
  `idimpianto` int(11) NOT NULL,
  `username` varchar(50) NOT NULL,
  `descrizione` text NOT NULL,
  `data_log` datetime NOT NULL,
   PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


INSERT INTO `zz_plugins` (`name`, `idmodule_from`, `idmodule_to`, `position`, `script`,  `path`) VALUES
('Storico', (SELECT id FROM zz_modules WHERE name = 'Anagrafiche'), (SELECT id FROM zz_modules WHERE name = 'Anagrafiche'), 'tab', 'log_utenti.php', 'log_anagrafiche'),
('Storico', (SELECT id FROM zz_modules WHERE name = 'Articoli'), (SELECT id FROM zz_modules WHERE name = 'Articoli' ), 'tab', 'log_utenti.php', 'log_articoli');

INSERT INTO `zz_plugins` (`name`, `idmodule_from`, `idmodule_to`, `position`, `script`,  `path`) VALUES
('Storico', (SELECT id FROM zz_modules WHERE name = 'Canoni Assistenza'), (SELECT id FROM zz_modules WHERE name = 'Canoni Assistenza'), 'tab', 'log_utenti.php', 'log_canoni');

INSERT INTO `zz_plugins` (`name`, `idmodule_from`, `idmodule_to`, `position`, `script`,  `path`) VALUES
('Storico', (SELECT id FROM zz_modules WHERE name = 'Installazioni'), (SELECT id FROM zz_modules WHERE name = 'Installazioni'), 'tab', 'log_utenti.php', 'log_installazioni');