ALTER TABLE  `categories` ADD  `flag_search` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT  '1' COMMENT  'Mostra campo Ricerca';

INSERT INTO  `options` (
`id` ,
`key` ,
`type` ,
`value`
)
VALUES (
NULL ,  'Global.google_url_shortener',  '',  'AIzaSyBYNhlV1ymtN_wPRTnR2B7yl9IffbhFEeE'
);

/* LINKS */
CREATE TABLE IF NOT EXISTS `links` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(150) NOT NULL,
  `description` text NOT NULL,
  `url` varchar(150) NOT NULL,
  `created` datetime NOT NULL,
  `modified` datetime NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

--
-- Struttura della tabella `categories_links`
--

CREATE TABLE IF NOT EXISTS `categories_links` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `category_id` int(11) NOT NULL,
  `link_id` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `category_id` (`category_id`),
  KEY `link_id` (`link_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

ALTER TABLE  `links` ADD  `flag_shortener` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT  '0' COMMENT  'indica se il link verrà accorciato' AFTER  `url`;

--
-- Limiti per le tabelle scaricate
--

--
-- Limiti per la tabella `categories_links`
--
ALTER TABLE `categories_links`
  ADD CONSTRAINT `categories_links_ibfk_2` FOREIGN KEY (`link_id`) REFERENCES `links` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `categories_links_ibfk_1` FOREIGN KEY (`category_id`) REFERENCES `categories` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
  
INSERT INTO  `permissions` (
`id` ,
`module` ,
`controller` ,
`action` ,
`row` ,
`flag_exclusive` ,
`level` ,
`created` ,
`modified`
)
VALUES (
NULL ,  'Base',  'links',  '*',  'base:links:*',  '0',  '70', NOW( ) , NOW( )
);

UPDATE  `items` SET  `description` =  'Links',
`level` =  '70' WHERE  `items`.`id` =6;

INSERT INTO  `jsfiles` (
`id` ,
`plugin` ,
`jsfile` ,
`jsmodule` ,
`jsfunction`
)
VALUES (
NULL , NULL ,  'manage_links',  'ManageLinks',  'init'
), (
NULL , NULL ,  'edit_link',  'EditLink',  'init'
);

INSERT INTO  `items_jsfiles` (
`id` ,
`jsfile_id` ,
`item_id` ,
`flag_main`
)
VALUES (
NULL ,  '11',  '6',  '1'
), (
NULL ,  '12',  '6',  '0'
);

UPDATE  `items` SET  `flag_active` =  '1' WHERE  `items`.`id` =6;

CREATE TABLE  `documents_pages` (
`id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`page_id` INT( 11 ) NOT NULL ,
`attachment_id` INT( 11 ) NOT NULL ,
`created` DATETIME NOT NULL ,
`modified` DATETIME NOT NULL ,
INDEX (  `page_id` )
) ENGINE = INNODB;

ALTER TABLE  `documents_pages` ADD INDEX (  `attachment_id` );

ALTER TABLE  `documents_pages` CHANGE  `attachment_id`  `attachment_id` INT( 11 ) UNSIGNED NOT NULL;

ALTER TABLE  `documents_pages` ADD FOREIGN KEY (  `page_id` ) REFERENCES  `pages` (
`id`
) ON DELETE CASCADE ON UPDATE CASCADE ;

ALTER TABLE  `documents_pages` ADD FOREIGN KEY (  `attachment_id` ) REFERENCES `attachments` (
`id`
) ON DELETE CASCADE ON UPDATE CASCADE ;

ALTER TABLE  `attachments` ADD  `original_name` VARCHAR( 255 ) NULL COMMENT  'eventuale nome originale' AFTER  `name`;

ALTER TABLE  `documents_pages` ADD  `description` VARCHAR( 255 ) NULL AFTER  `attachment_id`;

ALTER TABLE  `documents_pages` ADD  `flag_private` TINYINT UNSIGNED NOT NULL DEFAULT  '0' COMMENT  '1 = privato' AFTER  `description`;

INSERT INTO `permissions` (`id`, `module`, `controller`, `action`, `row`, `flag_exclusive`, `level`, `created`, `modified`) VALUES (NULL, 'MediaManager', 'Files', 'download', 'mediamanager:files:download', '0', '0', NOW(), NOW());