✅ $message"; } function echoError($message) { echo "
❌ $message
"; } // Beispielhafte DB-Verbindung (nur Dummy für Kontext) if (!isset($GLOBALS['mysql_con'])) { echoError("Keine Datenbankverbindung gefunden."); exit; } // Tabellen-Erstellung function create_tables() { $allSuccess = true; $queries = [ // Tabellenname => SQL "knowledgecenter_posts" => "CREATE TABLE IF NOT EXISTS knowledgecenter_posts ( id INT AUTO_INCREMENT PRIMARY KEY, created_at DATETIME DEFAULT CURRENT_TIMESTAMP, modified_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, modified_by VARCHAR(255) COMMENT 'Name des Main Contact', preview_inline TINYINT(1) NOT NULL DEFAULT 1 COMMENT '0 = keine Inline-Vorschau, 1 = Inline-Vorschau', background_color VARCHAR(9) NOT NULL DEFAULT '#FFFFFF', text_color VARCHAR(9) NOT NULL DEFAULT '#000000' ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;", "knowledgecenter_post_contacts" => "CREATE TABLE IF NOT EXISTS knowledgecenter_post_contacts ( id INT AUTO_INCREMENT PRIMARY KEY, post_id INT NOT NULL, main_contact_id INT NOT NULL, modified_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, created_at DATETIME DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (post_id) REFERENCES knowledgecenter_posts(id) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;", "knowledgecenter_post_mandant" => "CREATE TABLE IF NOT EXISTS knowledgecenter_post_mandant ( id INT AUTO_INCREMENT PRIMARY KEY, post_id INT NOT NULL, mandant_id INT NOT NULL, created_at DATETIME DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (post_id) REFERENCES knowledgecenter_posts(id) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;", "knowledgecenter_post_department" => "CREATE TABLE IF NOT EXISTS knowledgecenter_post_department ( id INT AUTO_INCREMENT PRIMARY KEY, post_id INT NOT NULL, department_id INT NOT NULL, created_at DATETIME DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (post_id) REFERENCES knowledgecenter_posts(id) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;", "knowledgecenter_post_files" => "CREATE TABLE IF NOT EXISTS knowledgecenter_post_files ( id INT AUTO_INCREMENT PRIMARY KEY, post_id INT NOT NULL, description VARCHAR(255), path VARCHAR(500), modified_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, created_at DATETIME DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (post_id) REFERENCES knowledgecenter_posts(id) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;", "knowledgecenter_post_role" => "CREATE TABLE IF NOT EXISTS knowledgecenter_post_role ( id INT AUTO_INCREMENT PRIMARY KEY, post_id INT NOT NULL, role_id INT NOT NULL, created_at DATETIME DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (post_id) REFERENCES knowledgecenter_posts(id) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;", "knowledgecenter_post_versions" => "CREATE TABLE IF NOT EXISTS knowledgecenter_post_versions ( id INT AUTO_INCREMENT PRIMARY KEY, post_id INT NOT NULL, version_number INT NOT NULL, language_id INT NOT NULL, title VARCHAR(255), image VARCHAR(255), teaser TEXT, content LONGTEXT, author_id INT, state TINYINT DEFAULT 1, modified_at DATETIME DEFAULT CURRENT_TIMESTAMP, valid_from DATETIME NULL, valid_until DATETIME NULL, background_color VARCHAR(9) NOT NULL DEFAULT '#FFFFFF', text_color VARCHAR(9) NOT NULL DEFAULT '#000000', FOREIGN KEY (post_id) REFERENCES knowledgecenter_posts(id) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;", "knowledgecenter_post_version_contacts" => "CREATE TABLE IF NOT EXISTS knowledgecenter_post_version_contacts ( id INT AUTO_INCREMENT PRIMARY KEY, version_id INT NOT NULL, contact_id INT NOT NULL, FOREIGN KEY (version_id) REFERENCES knowledgecenter_post_versions(id) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;", "knowledgecenter_categories_update" => "CREATE TABLE IF NOT EXISTS knowledgecenter_categories_update ( id INT AUTO_INCREMENT PRIMARY KEY, sorting INT DEFAULT 0, state TINYINT DEFAULT 1, modified_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, modified_by VARCHAR(255) COMMENT 'Name des Main Contact', created_at DATETIME DEFAULT CURRENT_TIMESTAMP ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;", "knowledgecenter_category_translations" => "CREATE TABLE IF NOT EXISTS knowledgecenter_category_translations ( id INT AUTO_INCREMENT PRIMARY KEY, category_id INT NOT NULL, language_id INT NOT NULL, title VARCHAR(255) NOT NULL, image VARCHAR(255), modified_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, created_at DATETIME DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (category_id) REFERENCES knowledgecenter_categories_update(id) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;", "knowledgecenter_category_post" => "CREATE TABLE IF NOT EXISTS knowledgecenter_category_post ( id INT AUTO_INCREMENT PRIMARY KEY, category_id INT NOT NULL, post_id INT NOT NULL, FOREIGN KEY (category_id) REFERENCES knowledgecenter_categories_update(id) ON DELETE CASCADE, FOREIGN KEY (post_id) REFERENCES knowledgecenter_posts(id) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;", "knowledgecenter_category_mandant" => "CREATE TABLE IF NOT EXISTS knowledgecenter_category_mandant ( id INT AUTO_INCREMENT PRIMARY KEY, category_id INT NOT NULL, mandant_id INT NOT NULL, created_at DATETIME DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (category_id) REFERENCES knowledgecenter_categories_update(id) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;", "knowledgecenter_category_department" => "CREATE TABLE IF NOT EXISTS knowledgecenter_category_department ( id INT AUTO_INCREMENT PRIMARY KEY, category_id INT NOT NULL, department_id INT NOT NULL, created_at DATETIME DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (category_id) REFERENCES knowledgecenter_categories_update(id) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;", "knowledgecenter_category_role" => "CREATE TABLE IF NOT EXISTS knowledgecenter_category_role ( id INT AUTO_INCREMENT PRIMARY KEY, category_id INT NOT NULL, role_id INT NOT NULL, created_at DATETIME DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (category_id) REFERENCES knowledgecenter_categories_update(id) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;", "knowledgecenter_post_comments" => "CREATE TABLE IF NOT EXISTS knowledgecenter_post_comments ( id INT AUTO_INCREMENT PRIMARY KEY, post_id INT NOT NULL, parent_id INT DEFAULT NULL, text TEXT NOT NULL, author_id INT NOT NULL COMMENT 'main_contact_id', modified_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, created_at DATETIME DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (post_id) REFERENCES knowledgecenter_posts(id) ON DELETE CASCADE, FOREIGN KEY (parent_id) REFERENCES knowledgecenter_post_comments(id) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;", "knowledgecenter_category_links" => "CREATE TABLE IF NOT EXISTS knowledgecenter_category_links ( id INT AUTO_INCREMENT PRIMARY KEY, parent_category_id INT NOT NULL, child_category_id INT NOT NULL, sorting INT DEFAULT 0, created_at DATETIME DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (parent_category_id) REFERENCES knowledgecenter_categories_update(id) ON DELETE CASCADE, FOREIGN KEY (child_category_id) REFERENCES knowledgecenter_categories_update(id) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;" ]; foreach ($queries as $name => $sql) { if (mysqli_query($GLOBALS['mysql_con'], $sql)) { echoSuccess("Tabelle $name wurde erfolgreich erstellt (oder existierte bereits)."); } else { echoError("Fehler beim Erstellen der Tabelle $name: " . mysqli_error($GLOBALS['mysql_con'])); $allSuccess = false; } } return $allSuccess; } // Ausführen der Tabellen-Erstellung if (create_tables()) { echoSuccess("✅ Alle Tabellen erfolgreich erstellt!"); } else { echoError("❌ Es gab Fehler beim Erstellen einzelner Tabellen."); } // Jetzt die zusätzlichen Indexe mittels ALTER TABLE setzen $indexQueries = [ // knowledgecenter_posts "ALTER TABLE knowledgecenter_posts ADD INDEX idx_created_at (created_at);", "ALTER TABLE knowledgecenter_posts ADD INDEX idx_modified_at (modified_at);", "ALTER TABLE knowledgecenter_posts ADD INDEX idx_modified_by (modified_by);", // knowledgecenter_post_contacts "ALTER TABLE knowledgecenter_post_contacts ADD INDEX idx_post_id (post_id);", "ALTER TABLE knowledgecenter_post_contacts ADD INDEX idx_main_contact_id (main_contact_id);", // knowledgecenter_post_mandant "ALTER TABLE knowledgecenter_post_mandant ADD INDEX idx_post_mandant (post_id, mandant_id);", // knowledgecenter_post_department "ALTER TABLE knowledgecenter_post_department ADD INDEX idx_post_department (post_id, department_id);", // knowledgecenter_post_files "ALTER TABLE knowledgecenter_post_files ADD INDEX idx_post_id (post_id);", // knowledgecenter_post_role "ALTER TABLE knowledgecenter_post_role ADD INDEX idx_post_role (post_id, role_id);", // knowledgecenter_post_versions "ALTER TABLE knowledgecenter_post_versions ADD INDEX idx_post_id (post_id);", "ALTER TABLE knowledgecenter_post_versions ADD INDEX idx_post_language (post_id, language_id);", // knowledgecenter_post_version_contacts "ALTER TABLE knowledgecenter_post_version_contacts ADD INDEX idx_version_contact (version_id, contact_id);", // knowledgecenter_categories_update "ALTER TABLE knowledgecenter_categories_update ADD INDEX idx_state_sorting (state, sorting);", "ALTER TABLE knowledgecenter_categories_update ADD INDEX idx_modified_at (modified_at);", "ALTER TABLE knowledgecenter_categories_update ADD INDEX idx_modified_by (modified_by);", // knowledgecenter_category_translations "ALTER TABLE knowledgecenter_category_translations ADD INDEX idx_category_language (category_id, language_id);", // knowledgecenter_category_post "ALTER TABLE knowledgecenter_category_post ADD INDEX idx_category_post (category_id, post_id);", // knowledgecenter_category_mandant "ALTER TABLE knowledgecenter_category_mandant ADD INDEX idx_category_mandant (category_id, mandant_id);", // knowledgecenter_category_department "ALTER TABLE knowledgecenter_category_department ADD INDEX idx_category_department (category_id, department_id);", // knowledgecenter_category_role "ALTER TABLE knowledgecenter_category_role ADD INDEX idx_category_role (category_id, role_id);", // knowledgecenter_post_comments "ALTER TABLE knowledgecenter_post_comments ADD INDEX idx_post_id (post_id);", "ALTER TABLE knowledgecenter_post_comments ADD INDEX idx_parent_id (parent_id);", // knowledgecenter_category_links "ALTER TABLE knowledgecenter_category_links ADD INDEX idx_parent_child (parent_category_id, child_category_id);" ]; foreach ($indexQueries as $query) { if (mysqli_query($GLOBALS['mysql_con'], $query)) { echoSuccess("Index erfolgreich erstellt: " . htmlspecialchars($query)); } else { echoError("Fehler beim Erstellen des Index: " . mysqli_error($GLOBALS['mysql_con']) . " - Query: " . htmlspecialchars($query)); } } // Überprüfen, ob die Spalte "post_id" in der Tabelle "main_certificate" existiert $checkQuery = "SHOW COLUMNS FROM main_certificate LIKE 'post_id'"; $checkResult = mysqli_query($GLOBALS['mysql_con'], $checkQuery); if ($checkResult && mysqli_num_rows($checkResult) == 0) { // Spalte existiert nicht – hinzufügen $alterQuery = "ALTER TABLE main_certificate ADD COLUMN post_id INT NOT NULL"; // oder NULL, je nach Anforderung if (mysqli_query($GLOBALS['mysql_con'], $alterQuery)) { echoSuccess("Spalte 'post_id' in Tabelle main_certificate erfolgreich hinzugefügt."); } else { echoError("Fehler beim Hinzufügen der Spalte 'post_id': " . mysqli_error($GLOBALS['mysql_con'])); } } else { echoSuccess("Spalte 'post_id' existiert bereits in main_certificate."); } // Array mit den Permissions, die hinzugefügt werden sollen $permissions = [ [ 'description' => 'Darf Wiki Modul installieren', 'code' => 'install_admin_kc', 'short_text' => '', 'only_main_mandant' => 1, 'default_active' => 0 ], [ 'description' => 'Darf Wiki Inhalte importieren', 'code' => 'import_admin_kc', 'short_text' => '', 'only_main_mandant' => 1, 'default_active' => 0 ], [ 'description' => 'Darf Wiki Beitragsliste sehen', 'code' => 'view_admin_kc_post_list', 'short_text' => '', 'only_main_mandant' => 1, 'default_active' => 0 ], [ 'description' => 'Darf Wiki Kategorie Admin Listen Items löschen', 'code' => 'delete_admin_kc_category_item', 'short_text' => '', 'only_main_mandant' => 1, 'default_active' => 0 ], [ 'description' => 'Darf Wiki Kategorie Admin Liste sehen', 'code' => 'view_admin_kc_category_list', 'short_text' => '', 'only_main_mandant' => 1, 'default_active' => 0 ], [ 'description' => 'Darf Wiki Kategorien erstellen', 'code' => 'create_admin_kc_category', 'short_text' => '', 'only_main_mandant' => 1, 'default_active' => 0 ], [ 'description' => 'Darf Wiki Kategorien bearbeiten', 'code' => 'edit_admin_kc_category', 'short_text' => '', 'only_main_mandant' => 1, 'default_active' => 0 ], [ 'description' => 'Darf neuen Wiki Beitrag erstellen', 'code' => 'create_admin_kc_post', 'short_text' => '', 'only_main_mandant' => 1, 'default_active' => 0 ], [ 'description' => 'Darf Wiki Beitragsversion ändern', 'code' => 'edit_admin_kc_post_version', 'short_text' => '', 'only_main_mandant' => 1, 'default_active' => 0 ], [ 'description' => 'Darf neue Wiki Beitragsversion erstellen', 'code' => 'create_admin_kc_post_version', 'short_text' => '', 'only_main_mandant' => 1, 'default_active' => 0 ], [ 'description' => 'Darf Wiki Beitragsversion löschen', 'code' => 'delete_admin_kc_post_version', 'short_text' => '', 'only_main_mandant' => 1, 'default_active' => 0 ], [ 'description' => 'Darf Wiki Beitragsdateien löschen', 'code' => 'delete_admin_kc_post_file', 'short_text' => '', 'only_main_mandant' => 1, 'default_active' => 0 ], [ 'description' => 'Darf Wiki Beitragsdateien hinzufügen', 'code' => 'add_admin_kc_post_file', 'short_text' => '', 'only_main_mandant' => 1, 'default_active' => 0 ], [ 'description' => 'Darf Wiki Beitrags Ansprechpartner verwalten', 'code' => 'manage_admin_kc_post_contacts', 'short_text' => '', 'only_main_mandant' => 1, 'default_active' => 0 ], [ 'description' => 'Darf Wiki Beitrags Einstellungen sehen', 'code' => 'view_admin_kc_post_settings', 'short_text' => '', 'only_main_mandant' => 1, 'default_active' => 0 ], [ 'description' => 'Darf Wiki Beitrags Einstellungen speichern', 'code' => 'save_admin_kc_post_settings', 'short_text' => '', 'only_main_mandant' => 1, 'default_active' => 0 ] ]; // Iteriere über das Array und füge jede Permission ein: foreach ($permissions as $perm) { // Stelle sicher, dass Zeichenketten richtig escaped werden: $description = mysqli_real_escape_string($GLOBALS['mysql_con'], $perm['description']); $code = mysqli_real_escape_string($GLOBALS['mysql_con'], $perm['code']); $short_text = mysqli_real_escape_string($GLOBALS['mysql_con'], $perm['short_text']); $only_main_mandant = (int) $perm['only_main_mandant']; $default_active = (int) $perm['default_active']; // Zuerst prüfen, ob eine Permission mit diesem Code bereits existiert. $checkSql = "SELECT id FROM main_permission WHERE code = '$code' LIMIT 1"; $checkResult = mysqli_query($GLOBALS['mysql_con'], $checkSql); if ($checkResult && mysqli_num_rows($checkResult) > 0) { // Falls vorhanden, kannst Du eine Erfolgsmeldung anzeigen oder den Eintrag überspringen. echoSuccess("Permission '$description' existiert bereits."); continue; // Weitere Verarbeitung überspringen. } // Falls nicht vorhanden, führe das INSERT aus: $insertSql = "INSERT INTO `main_permission` (`id`, `description`, `code`, `short_text`, `only_main_mandant`, `default_active`) VALUES (NULL, '$description', '$code', '$short_text', '$only_main_mandant', '$default_active')"; if (mysqli_query($GLOBALS['mysql_con'], $insertSql)) { echoSuccess("Permission '$description' wurde erfolgreich hinzugefügt."); } else { echoError("Fehler beim Hinzufügen der Permission '$description': " . mysqli_error($GLOBALS['mysql_con'])); } } ?>