<?php
$db_update['indizies'][17]['custom_levels'] = "ALTER TABLE `custom_levels` ADD UNIQUE(`language`, `url`);";
$db_update['indizies'][24]['languages'] = "ALTER TABLE `languages` DROP `language`;";
$db_update['data'][24]['languages'] = "
ALTER TABLE `languages` CHANGE `title` `label` VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL;
UPDATE `languages` SET `label` = 'LABEL_GERMAN' WHERE `iso` = 'de';";


$db_update['data'][49]['custom_options'] = "UPDATE `custom_options` SET `value` = '1' WHERE `title` = 'c_modules';";
$db_update['data'][49]['frontend_options'] = "UPDATE `frontend_options` SET `value` = '1' WHERE `title` = 'c_modules';";


$db_update['data'][81]['custom_options'] = "ALTER TABLE `custom_options` ADD UNIQUE(`title`);";
$db_update['data'][82]['frontend_options'] = "ALTER TABLE `frontend_options` ADD UNIQUE(`title`);";



$db_update['structure'][88]['custom_levels_links'] = "
CREATE TABLE `custom_levels_links` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `id_module` int(11) DEFAULT NULL,
  `guidv4` varchar(36) DEFAULT NULL,
  PRIMARY KEY (`id`), UNIQUE KEY `id_module` (`id_module`,`guidv4`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;";



$db_update['data']['1.0.42']['custom_levels'] = "ALTER TABLE `custom_levels` ADD `class` VARCHAR(255) NULL DEFAULT NULL AFTER `linktext`;";


$db_update['data']['1.0.98']['settings_users'] = "
SET @sql := (
  SELECT IF(
    EXISTS (
      SELECT 1
      FROM INFORMATION_SCHEMA.COLUMNS
      WHERE TABLE_SCHEMA = DATABASE()
        AND TABLE_NAME   = 'settings_users'
        AND COLUMN_NAME  = 'c_monitor'
    ),
    'ALTER TABLE `settings_users` CHANGE COLUMN `c_monitor` `c_viewer` ENUM(''0'',''1'') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT ''0'';',
    'SELECT ''no-op: c_monitor not found'';'
  )
);

PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;";


$db_update['data']['1.0.98']['backend_modules'] = "
SET @sql := (
  SELECT IF(
    EXISTS (
      SELECT 1
      FROM INFORMATION_SCHEMA.COLUMNS
      WHERE TABLE_SCHEMA = DATABASE()
        AND TABLE_NAME   = 'backend_modules'
        AND COLUMN_NAME  = 'c_monitor'
    ),
    'ALTER TABLE `backend_modules` CHANGE COLUMN `c_monitor` `c_viewer` ENUM(''0'',''1'') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT ''0'';',
    'SELECT ''no-op: c_monitor not found'';'
  )
);

PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;";

$db_update['data']['1.0.98']['frontend_modules'] = "
SET @sql := (
  SELECT IF(
    EXISTS (
      SELECT 1
      FROM INFORMATION_SCHEMA.COLUMNS
      WHERE TABLE_SCHEMA = DATABASE()
        AND TABLE_NAME   = 'frontend_modules'
        AND COLUMN_NAME  = 'c_monitor'
    ),
    'ALTER TABLE `frontend_modules` CHANGE COLUMN `c_monitor` `c_viewer` ENUM(''0'',''1'') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT ''0'';',
    'SELECT ''no-op: c_monitor not found'';'
  )
);

PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;";

$db_update['data']['1.0.98']['settings_modules'] = "
SET @sql := (
  SELECT IF(
    EXISTS (
      SELECT 1
      FROM INFORMATION_SCHEMA.COLUMNS
      WHERE TABLE_SCHEMA = DATABASE()
        AND TABLE_NAME   = 'settings_modules'
        AND COLUMN_NAME  = 'c_monitor'
    ),
    'ALTER TABLE `settings_modules` CHANGE COLUMN `c_monitor` `c_viewer` ENUM(''0'',''1'') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT ''0'';',
    'SELECT ''no-op: c_monitor not found'';'
  )
);

PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;";

$db_update['data']['1.0.98']['bookings_modules'] = "
SET @sql := (
  SELECT IF(
    EXISTS (
      SELECT 1
      FROM INFORMATION_SCHEMA.COLUMNS
      WHERE TABLE_SCHEMA = DATABASE()
        AND TABLE_NAME   = 'bookings_modules'
        AND COLUMN_NAME  = 'c_monitor'
    ),
    'ALTER TABLE `bookings_modules` CHANGE COLUMN `c_monitor` `c_viewer` ENUM(''0'',''1'') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT ''0'';',
    'SELECT ''no-op: c_monitor not found'';'
  )
);

PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;";

$db_update['data']['1.0.98']['content_modules'] = "
SET @sql := (
  SELECT IF(
    EXISTS (
      SELECT 1
      FROM INFORMATION_SCHEMA.COLUMNS
      WHERE TABLE_SCHEMA = DATABASE()
        AND TABLE_NAME   = 'content_modules'
        AND COLUMN_NAME  = 'c_monitor'
    ),
    'ALTER TABLE `content_modules` CHANGE COLUMN `c_monitor` `c_viewer` ENUM(''0'',''1'') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT ''0'';',
    'SELECT ''no-op: c_monitor not found'';'
  )
);

PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;";


$db_update['data']['1.0.98']['custom_modules'] = "
SET @sql := (
  SELECT IF(
    EXISTS (
      SELECT 1
      FROM INFORMATION_SCHEMA.COLUMNS
      WHERE TABLE_SCHEMA = DATABASE()
        AND TABLE_NAME   = 'custom_modules'
        AND COLUMN_NAME  = 'c_monitor'
    ),
    'ALTER TABLE `custom_modules` CHANGE COLUMN `c_monitor` `c_viewer` ENUM(''0'',''1'') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT ''0'';',
    'SELECT ''no-op: c_monitor not found'';'
  )
);

PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;";

$db_update['data']['1.0.98']['customers_modules'] = "
SET @sql := (
  SELECT IF(
    EXISTS (
      SELECT 1
      FROM INFORMATION_SCHEMA.COLUMNS
      WHERE TABLE_SCHEMA = DATABASE()
        AND TABLE_NAME   = 'customers_modules'
        AND COLUMN_NAME  = 'c_monitor'
    ),
    'ALTER TABLE `customers_modules` CHANGE COLUMN `c_monitor` `c_viewer` ENUM(''0'',''1'') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT ''0'';',
    'SELECT ''no-op: c_monitor not found'';'
  )
);

PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;";

$db_update['data']['1.0.98']['encrypt_modules'] = "
SET @sql := (
  SELECT IF(
    EXISTS (
      SELECT 1
      FROM INFORMATION_SCHEMA.COLUMNS
      WHERE TABLE_SCHEMA = DATABASE()
        AND TABLE_NAME   = 'encrypt_modules'
        AND COLUMN_NAME  = 'c_monitor'
    ),
    'ALTER TABLE `encrypt_modules` CHANGE COLUMN `c_monitor` `c_viewer` ENUM(''0'',''1'') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT ''0'';',
    'SELECT ''no-op: c_monitor not found'';'
  )
);

PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;";

$db_update['data']['1.0.98']['events_modules'] = "
SET @sql := (
  SELECT IF(
    EXISTS (
      SELECT 1
      FROM INFORMATION_SCHEMA.COLUMNS
      WHERE TABLE_SCHEMA = DATABASE()
        AND TABLE_NAME   = 'events_modules'
        AND COLUMN_NAME  = 'c_monitor'
    ),
    'ALTER TABLE `events_modules` CHANGE COLUMN `c_monitor` `c_viewer` ENUM(''0'',''1'') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT ''0'';',
    'SELECT ''no-op: c_monitor not found'';'
  )
);

PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;";

$db_update['data']['1.0.98']['faq_modules'] = "
SET @sql := (
  SELECT IF(
    EXISTS (
      SELECT 1
      FROM INFORMATION_SCHEMA.COLUMNS
      WHERE TABLE_SCHEMA = DATABASE()
        AND TABLE_NAME   = 'faq_modules'
        AND COLUMN_NAME  = 'c_monitor'
    ),
    'ALTER TABLE `faq_modules` CHANGE COLUMN `c_monitor` `c_viewer` ENUM(''0'',''1'') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT ''0'';',
    'SELECT ''no-op: c_monitor not found'';'
  )
);

PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;";

$db_update['data']['1.0.98']['forms_modules'] = "
SET @sql := (
  SELECT IF(
    EXISTS (
      SELECT 1
      FROM INFORMATION_SCHEMA.COLUMNS
      WHERE TABLE_SCHEMA = DATABASE()
        AND TABLE_NAME   = 'forms_modules'
        AND COLUMN_NAME  = 'c_monitor'
    ),
    'ALTER TABLE `forms_modules` CHANGE COLUMN `c_monitor` `c_viewer` ENUM(''0'',''1'') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT ''0'';',
    'SELECT ''no-op: c_monitor not found'';'
  )
);

PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;";

$db_update['data']['1.0.98']['gallery_modules'] = "
SET @sql := (
  SELECT IF(
    EXISTS (
      SELECT 1
      FROM INFORMATION_SCHEMA.COLUMNS
      WHERE TABLE_SCHEMA = DATABASE()
        AND TABLE_NAME   = 'gallery_modules'
        AND COLUMN_NAME  = 'c_monitor'
    ),
    'ALTER TABLE `gallery_modules` CHANGE COLUMN `c_monitor` `c_viewer` ENUM(''0'',''1'') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT ''0'';',
    'SELECT ''no-op: c_monitor not found'';'
  )
);

PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;";

$db_update['data']['1.0.98']['invoices_modules'] = "
SET @sql := (
  SELECT IF(
    EXISTS (
      SELECT 1
      FROM INFORMATION_SCHEMA.COLUMNS
      WHERE TABLE_SCHEMA = DATABASE()
        AND TABLE_NAME   = 'invoices_modules'
        AND COLUMN_NAME  = 'c_monitor'
    ),
    'ALTER TABLE `invoices_modules` CHANGE COLUMN `c_monitor` `c_viewer` ENUM(''0'',''1'') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT ''0'';',
    'SELECT ''no-op: c_monitor not found'';'
  )
);

PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;";

$db_update['data']['1.0.98']['library_modules'] = "
SET @sql := (
  SELECT IF(
    EXISTS (
      SELECT 1
      FROM INFORMATION_SCHEMA.COLUMNS
      WHERE TABLE_SCHEMA = DATABASE()
        AND TABLE_NAME   = 'library_modules'
        AND COLUMN_NAME  = 'c_monitor'
    ),
    'ALTER TABLE `library_modules` CHANGE COLUMN `c_monitor` `c_viewer` ENUM(''0'',''1'') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT ''0'';',
    'SELECT ''no-op: c_monitor not found'';'
  )
);

PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;";

$db_update['data']['1.0.98']['news_modules'] = "
SET @sql := (
  SELECT IF(
    EXISTS (
      SELECT 1
      FROM INFORMATION_SCHEMA.COLUMNS
      WHERE TABLE_SCHEMA = DATABASE()
        AND TABLE_NAME   = 'news_modules'
        AND COLUMN_NAME  = 'c_monitor'
    ),
    'ALTER TABLE `news_modules` CHANGE COLUMN `c_monitor` `c_viewer` ENUM(''0'',''1'') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT ''0'';',
    'SELECT ''no-op: c_monitor not found'';'
  )
);

PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;";

$db_update['data']['1.0.98']['newsletter_modules'] = "
SET @sql := (
  SELECT IF(
    EXISTS (
      SELECT 1
      FROM INFORMATION_SCHEMA.COLUMNS
      WHERE TABLE_SCHEMA = DATABASE()
        AND TABLE_NAME   = 'newsletter_modules'
        AND COLUMN_NAME  = 'c_monitor'
    ),
    'ALTER TABLE `newsletter_modules` CHANGE COLUMN `c_monitor` `c_viewer` ENUM(''0'',''1'') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT ''0'';',
    'SELECT ''no-op: c_monitor not found'';'
  )
);

PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;";

$db_update['data']['1.0.98']['orders_modules'] = "
SET @sql := (
  SELECT IF(
    EXISTS (
      SELECT 1
      FROM INFORMATION_SCHEMA.COLUMNS
      WHERE TABLE_SCHEMA = DATABASE()
        AND TABLE_NAME   = 'orders_modules'
        AND COLUMN_NAME  = 'c_monitor'
    ),
    'ALTER TABLE `orders_modules` CHANGE COLUMN `c_monitor` `c_viewer` ENUM(''0'',''1'') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT ''0'';',
    'SELECT ''no-op: c_monitor not found'';'
  )
);

PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;";

$db_update['data']['1.0.98']['products_modules'] = "
SET @sql := (
  SELECT IF(
    EXISTS (
      SELECT 1
      FROM INFORMATION_SCHEMA.COLUMNS
      WHERE TABLE_SCHEMA = DATABASE()
        AND TABLE_NAME   = 'products_modules'
        AND COLUMN_NAME  = 'c_monitor'
    ),
    'ALTER TABLE `products_modules` CHANGE COLUMN `c_monitor` `c_viewer` ENUM(''0'',''1'') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT ''0'';',
    'SELECT ''no-op: c_monitor not found'';'
  )
);

PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;";

$db_update['data']['1.0.98']['slider_modules'] = "
SET @sql := (
  SELECT IF(
    EXISTS (
      SELECT 1
      FROM INFORMATION_SCHEMA.COLUMNS
      WHERE TABLE_SCHEMA = DATABASE()
        AND TABLE_NAME   = 'slider_modules'
        AND COLUMN_NAME  = 'c_monitor'
    ),
    'ALTER TABLE `slider_modules` CHANGE COLUMN `c_monitor` `c_viewer` ENUM(''0'',''1'') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT ''0'';',
    'SELECT ''no-op: c_monitor not found'';'
  )
);

PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;";

$db_update['data']['1.0.98']['teaser_modules'] = "
SET @sql := (
  SELECT IF(
    EXISTS (
      SELECT 1
      FROM INFORMATION_SCHEMA.COLUMNS
      WHERE TABLE_SCHEMA = DATABASE()
        AND TABLE_NAME   = 'teaser_modules'
        AND COLUMN_NAME  = 'c_monitor'
    ),
    'ALTER TABLE `teaser_modules` CHANGE COLUMN `c_monitor` `c_viewer` ENUM(''0'',''1'') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT ''0'';',
    'SELECT ''no-op: c_monitor not found'';'
  )
);

PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;";

$db_update['data']['1.0.98']['ticker_modules'] = "
SET @sql := (
  SELECT IF(
    EXISTS (
      SELECT 1
      FROM INFORMATION_SCHEMA.COLUMNS
      WHERE TABLE_SCHEMA = DATABASE()
        AND TABLE_NAME   = 'ticker_modules'
        AND COLUMN_NAME  = 'c_monitor'
    ),
    'ALTER TABLE `ticker_modules` CHANGE COLUMN `c_monitor` `c_viewer` ENUM(''0'',''1'') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT ''0'';',
    'SELECT ''no-op: c_monitor not found'';'
  )
);

PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;";