-- +--------------------------------------------------------------------+
-- | CiviCRM version 5                                                  |
-- +--------------------------------------------------------------------+
-- | Copyright CiviCRM LLC (c) 2004-2019                                |
-- +--------------------------------------------------------------------+
-- | This file is a part of CiviCRM.                                    |
-- |                                                                    |
-- | CiviCRM is free software; you can copy, modify, and distribute it  |
-- | under the terms of the GNU Affero General Public License           |
-- | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
-- |                                                                    |
-- | CiviCRM is distributed in the hope that it will be useful, but     |
-- | WITHOUT ANY WARRANTY; without even the implied warranty of         |
-- | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
-- | See the GNU Affero General Public License for more details.        |
-- |                                                                    |
-- | You should have received a copy of the GNU Affero General Public   |
-- | License and the CiviCRM Licensing Exception along                  |
-- | with this program; if not, contact CiviCRM LLC                     |
-- | at info[AT]civicrm[DOT]org. If you have questions about the        |
-- | GNU Affero General Public License or the licensing of CiviCRM,     |
-- | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
-- +--------------------------------------------------------------------+
--
-- Generated from drop.tpl
-- DO NOT EDIT.  Generated by CRM_Core_CodeGen
--
-- /*******************************************************
-- *
-- * Clean up the exisiting tables
-- *
-- *******************************************************/

SET FOREIGN_KEY_CHECKS = 0;

DROP TABLE IF EXISTS `civicrm_event_calendar_event_type`;

DROP TABLE IF EXISTS `civicrm_event_calendar`;

SET FOREIGN_KEY_CHECKS = 1;

-- /*******************************************************
-- *
-- * Create new tables
-- *
-- *******************************************************/
--
-- /*******************************************************
-- *
-- * civicrm_event_calendar
-- *
-- * Stores Event Calendar parameters for display
-- *
-- *******************************************************/
CREATE TABLE `civicrm_event_calendar` (
        `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'Unique EventCalendar ID',
        `calendar_title` varchar(255) COMMENT 'Calendar Title',
        `show_past_events` tinyint COMMENT 'Show Past Events',
        `show_end_date` tinyint COMMENT 'Show End Date',
        `show_public_events` tinyint COMMENT 'Show Only Public or All',
        `events_by_month` tinyint COMMENT 'Use the Month param in the calendar',
        `event_timings` tinyint COMMENT 'Show the event timing',
        `events_from_month` int unsigned COMMENT 'How many months to show events',
        `event_type_filters` tinyint COMMENT 'Whether to show event type filters',
        `week_begins_from_day` tinyint COMMENT 'Show week begins from day',
        `recurring_event` tinyint COMMENT 'Show recurring events',
        `enrollment_status` tinyint COMMENT 'Show enrollment status',
        `saved_search_id` int(11) COMMENT 'Filter results by this saved search',
        PRIMARY KEY (`id`)
);

-- /*******************************************************
-- *
-- * civicrm_event_calendar_event_type
-- *
-- * Event types and colors, FK to Event Calendar ID
-- *
-- *******************************************************/
CREATE TABLE `civicrm_event_calendar_event_type` (
        `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'Unique EventCalendarEventType ID',
        `event_calendar_id` int unsigned COMMENT 'FK to Event Calendar',
        `event_type` int unsigned COMMENT 'Event Type id',
        `event_color` varchar(255) COMMENT 'Hex code for event type display color',
        PRIMARY KEY (`id`),
        CONSTRAINT FK_civicrm_event_calendar_event_type_event_calendar_id FOREIGN KEY (`event_calendar_id`) REFERENCES `civicrm_event_calendar`(`id`) ON DELETE CASCADE
);

-- SELECT @domain_id := min(id) FROM civicrm_domain;
-- SELECT @administerID    := MAX(id) FROM civicrm_navigation where name = 'Events';
-- SELECT @adminCampaignWeight := MAX(weight)+1 FROM civicrm_navigation where parent_id = @administerID;
-- INSERT INTO civicrm_navigation
--     ( domain_id, url, label, name, permission, permission_operator, parent_id, is_active, has_separator, weight )
-- VALUES
--     ( @domain_id,'civicrm/showevents', 'Show Events Calendar', 'Show Events Calendar', 'view event info', 'AND', @administerID, '1', NULL, @adminCampaignWeight );
-- SELECT @domain_id := min(id) FROM civicrm_domain;
-- SELECT @administerID    := MAX(id) FROM civicrm_navigation where name = 'CiviEvent';
-- SELECT @adminCampaignWeight := MAX(weight)+1 FROM civicrm_navigation where parent_id = @administerID;
-- INSERT INTO civicrm_navigation
--     ( domain_id, url, label, name, permission, permission_operator, parent_id, is_active, has_separator, weight )
-- VALUES
-- ( @domain_id,'civicrm/admin/event-calendar', 'Event Calendar Settings', 'Event Calendar Settings', 'administer CiviCRM', 'AND', @administerID, '1', NULL, @adminCampaignWeight );