User soll Gruppe und Forum erstellen dürfen

Fragen zu allen Themen rund ums Programmieren außerhalb von phpBB können hier gestellt werden - auch zu anderen Programmiersprachen oder Software wie Webservern und Editoren.
Antworten
Benutzeravatar
Pofi
Mitglied
Beiträge: 252
Registriert: 06.10.2007 10:17
Wohnort: Wuppertal
Kontaktdaten:

User soll Gruppe und Forum erstellen dürfen

Beitrag von Pofi »

Moin :-D

ich versuche den ganzen Tag schon etwas zu basteln. Auf unserer Seite gibt es eine Benutzergruppe, die nennt sich Dozenten.

Diese Dozenten sollen Benutzergruppen erstellen dürfen und gleichzeitig ein Forum.
Es handelt sich um Ausbildungsforen. Jeder Kurs soll also eine eigene Gruppe mit dazugehörigem Forum erhalten. Gruppenleiter ist immer der Dozent, der diese Gruppe erstellt hat.

Das mit den Gruppen habe bereits hinbekommen, auch wenn mir einige Dinge in der SQL unklar waren. Im ACP bekomme ich die Gruppen jedenfalls angezeigt.

Code: Alles auswählen

$sql = "SELECT * FROM phpbb_groups ORDER BY group_id DESC LIMIT 1";
    foreach ($pdo->query($sql) as $row) {
        $letzte_group_id = $row['group_id'];
    }
    $group_id = $letzte_group_id + 1;
    // Die neue Benutzergruppe wird erstellt.
    $statement = $pdo->prepare("INSERT INTO phpbb_groups (group_id, group_type, group_founder_manage, group_skip_auth, group_name, group_desc, group_desc_bitfield, group_desc_options, group_desc_uid, group_display, group_avatar, group_avatar_type, group_avatar_width, group_avatar_height, group_rank, group_colour, group_sig_chars, group_receive_pm, group_message_limit, group_legend, group_max_recipients) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
    $statement->execute(array($group_id, '1', '0', '0', $gruppenname, '', '', '7', '', '0', '', '', '0', '0', '0', '', '0', '1', '0', '0', '0'));
    // Gruppenleiter festlegen.
    $statement = $pdo->prepare("INSERT INTO phpbb_user_group (group_id, user_id, group_leader, user_pending) VALUES (?, ?, ?, ?)");
    $statement->execute(array($group_id, $userid, '1', '0'));
Wo ich jetzt aber total verzweifel, ist die Sache mit dem Forum. Ich habe es hinbekommen, dass im ACP ein Forum angezeigt wird, aber nur, wenn ich es direkt anwähle. Möchte ich die Berechtigungen ändern, sehe ich nichts... Also habe ich irgendwo einen Bock drinnen...

Code: Alles auswählen

$sql = "SELECT * FROM phpbb_forums ORDER BY forum_id DESC LIMIT 1";
    foreach ($pdo->query($sql) as $row) {
        $letzte_forum_id = $row['forum_id'];
        $letzte_left_id = $row['left_id'];
        $letzte_right_id = $row['right_id'];
    }
    $forum_id = $letzte_forum_id + 1;
    $left_id = $letzte_left_id + 2;
    $right_id = $letzte_right_id + 2;
    // Das neue Gruppenforum wird erstellt.
    $statement = $pdo->prepare("INSERT INTO phpbb_forums (forum_id, parent_id, left_id, right_id, forum_parents, forum_name, forum_desc, forum_desc_bitfield, forum_desc_options, forum_desc_uid, forum_link, forum_password, forum_style, forum_image, forum_rules, forum_rules_link, forum_rules_bitfield, forum_rules_options, forum_rules_uid, forum_topics_per_page, forum_type, forum_status, forum_last_post_id, forum_last_poster_id, forum_last_post_subject, forum_last_post_time, forum_last_poster_name, forum_last_poster_colour, forum_flags, display_on_index, enable_indexing, enable_icons, enable_prune, prune_next, prune_days, prune_viewed, prune_freq, display_subforum_list, forum_options, forum_posts_approved, forum_posts_unapproved, forum_posts_softdeleted, forum_topics_approved, forum_topics_unapproved, forum_topics_softdeleted, enable_shadow_prune, prune_shadow_days, prune_shadow_freq, prune_shadow_next) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
    $statement->execute(array($forum_id, '114', $left_id, $right_id, '0', $gruppenname, $group_id, '', '7', '', '', '', '0', '', '', '', '', '7', '', '0', '1', '0', '0', '0', '', '0', '', '', '48', '0', '1', '0', '0', '0', '7', '7', '1', '1', '0', '0', '0', '0', '0', '0', '0', '0', '7', '1', '0'));
    // Berechtigungen festlegen
    // Gruppenmitglieder
    $statement = $pdo->prepare("INSERT INTO phpbb_acl_groups (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES (?, ?, ?, ?, ?)");
    $statement->execute(array($group_id, $forum_id, '0', '14', '0'));
    // Moderatoren
    $statement = $pdo->prepare("INSERT INTO phpbb_acl_groups (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES (?, ?, ?, ?, ?)");
    $statement->execute(array('4', $forum_id, '0', '14', '0'));
    // Administratoren
    $statement = $pdo->prepare("INSERT INTO phpbb_acl_groups (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES (?, ?, ?, ?, ?)");
    $statement->execute(array('5', $forum_id, '0', '14', '0'));
    $statement = $pdo->prepare("INSERT INTO phpbb_acl_groups (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES (?, ?, ?, ?, ?)");
    $statement->execute(array('5', $forum_id, '1', '0', '1'));
    $statement = $pdo->prepare("INSERT INTO phpbb_acl_groups (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES (?, ?, ?, ?, ?)");
    $statement->execute(array('5', $forum_id, '2', '0', '1'));
    $statement = $pdo->prepare("INSERT INTO phpbb_acl_groups (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES (?, ?, ?, ?, ?)");
    $statement->execute(array('5', $forum_id, '3', '0', '1'));
    $statement = $pdo->prepare("INSERT INTO phpbb_acl_groups (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES (?, ?, ?, ?, ?)");
    $statement->execute(array('5', $forum_id, '4', '0', '1'));
    $statement = $pdo->prepare("INSERT INTO phpbb_acl_groups (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES (?, ?, ?, ?, ?)");
    $statement->execute(array('5', $forum_id, '5', '0', '1'));
    $statement = $pdo->prepare("INSERT INTO phpbb_acl_groups (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES (?, ?, ?, ?, ?)");
    $statement->execute(array('5', $forum_id, '6', '0', '1'));
    $statement = $pdo->prepare("INSERT INTO phpbb_acl_groups (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES (?, ?, ?, ?, ?)");
    $statement->execute(array('5', $forum_id, '7', '0', '1'));
    $statement = $pdo->prepare("INSERT INTO phpbb_acl_groups (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES (?, ?, ?, ?, ?)");
    $statement->execute(array('5', $forum_id, '8', '0', '1'));
    $statement = $pdo->prepare("INSERT INTO phpbb_acl_groups (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES (?, ?, ?, ?, ?)");
    $statement->execute(array('5', $forum_id, '9', '0', '1'));
    $statement = $pdo->prepare("INSERT INTO phpbb_acl_groups (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES (?, ?, ?, ?, ?)");
    $statement->execute(array('5', $forum_id, '10', '0', '1'));
    $statement = $pdo->prepare("INSERT INTO phpbb_acl_groups (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES (?, ?, ?, ?, ?)");
    $statement->execute(array('5', $forum_id, '11', '0', '1'));
    $statement = $pdo->prepare("INSERT INTO phpbb_acl_groups (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES (?, ?, ?, ?, ?)");
    $statement->execute(array('5', $forum_id, '12', '0', '1'));
    $statement = $pdo->prepare("INSERT INTO phpbb_acl_groups (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES (?, ?, ?, ?, ?)");
    $statement->execute(array('5', $forum_id, '13', '0', '1'));
    $statement = $pdo->prepare("INSERT INTO phpbb_acl_groups (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES (?, ?, ?, ?, ?)");
    $statement->execute(array('5', $forum_id, '14', '0', '1'));
    $statement = $pdo->prepare("INSERT INTO phpbb_acl_groups (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES (?, ?, ?, ?, ?)");
    $statement->execute(array('5', $forum_id, '15', '0', '1'));
    $statement = $pdo->prepare("INSERT INTO phpbb_acl_groups (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES (?, ?, ?, ?, ?)");
    $statement->execute(array('5', $forum_id, '16', '0', '1'));
    $statement = $pdo->prepare("INSERT INTO phpbb_acl_groups (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES (?, ?, ?, ?, ?)");
    $statement->execute(array('5', $forum_id, '17', '0', '1'));
    $statement = $pdo->prepare("INSERT INTO phpbb_acl_groups (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES (?, ?, ?, ?, ?)");
    $statement->execute(array('5', $forum_id, '18', '0', '1'));
    $statement = $pdo->prepare("INSERT INTO phpbb_acl_groups (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES (?, ?, ?, ?, ?)");
    $statement->execute(array('5', $forum_id, '19', '0', '1'));
    $statement = $pdo->prepare("INSERT INTO phpbb_acl_groups (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES (?, ?, ?, ?, ?)");
    $statement->execute(array('5', $forum_id, '20', '0', '1'));
    $statement = $pdo->prepare("INSERT INTO phpbb_acl_groups (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES (?, ?, ?, ?, ?)");
    $statement->execute(array('5', $forum_id, '21', '0', '1'));
    $statement = $pdo->prepare("INSERT INTO phpbb_acl_groups (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES (?, ?, ?, ?, ?)");
    $statement->execute(array('5', $forum_id, '22', '0', '1'));
    $statement = $pdo->prepare("INSERT INTO phpbb_acl_groups (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES (?, ?, ?, ?, ?)");
    $statement->execute(array('5', $forum_id, '23', '0', '1'));
    $statement = $pdo->prepare("INSERT INTO phpbb_acl_groups (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES (?, ?, ?, ?, ?)");
    $statement->execute(array('5', $forum_id, '24', '0', '1'));
    $statement = $pdo->prepare("INSERT INTO phpbb_acl_groups (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES (?, ?, ?, ?, ?)");
    $statement->execute(array('5', $forum_id, '25', '0', '1'));
    $statement = $pdo->prepare("INSERT INTO phpbb_acl_groups (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES (?, ?, ?, ?, ?)");
    $statement->execute(array('5', $forum_id, '26', '0', '1'));
    $statement = $pdo->prepare("INSERT INTO phpbb_acl_groups (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES (?, ?, ?, ?, ?)");
    $statement->execute(array('5', $forum_id, '27', '0', '1'));
    $statement = $pdo->prepare("INSERT INTO phpbb_acl_groups (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES (?, ?, ?, ?, ?)");
    $statement->execute(array('5', $forum_id, '28', '0', '1'));
    $statement = $pdo->prepare("INSERT INTO phpbb_acl_groups (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES (?, ?, ?, ?, ?)");
    $statement->execute(array('5', $forum_id, '29', '0', '1'));
    $statement = $pdo->prepare("INSERT INTO phpbb_acl_groups (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES (?, ?, ?, ?, ?)");
    $statement->execute(array('5', $forum_id, '30', '0', '1'));
    $statement = $pdo->prepare("INSERT INTO phpbb_acl_groups (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES (?, ?, ?, ?, ?)");
    $statement->execute(array('5', $forum_id, '31', '0', '1'));
    $statement = $pdo->prepare("INSERT INTO phpbb_acl_groups (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES (?, ?, ?, ?, ?)");
    $statement->execute(array('5', $forum_id, '32', '0', '1'));
    $statement = $pdo->prepare("INSERT INTO phpbb_acl_groups (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES (?, ?, ?, ?, ?)");
    $statement->execute(array('5', $forum_id, '164', '0', '1'));
    $statement = $pdo->prepare("INSERT INTO phpbb_acl_groups (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES (?, ?, ?, ?, ?)");
    $statement->execute(array('5', $forum_id, '191', '0', '1'));
Zunächst habe ich keine Ahnung, wofür die phpbb_acl_groups überhaupt da ist. Uber den Rest meines codierten Meisterwerkes möchte ich garnicht erst reden... :roll:

Es gibt mit Sicherheit eine bessere Lösung. Aber Google versteht mich nicht so recht... :x Ich suche nach einer einfacheren Art ein Forum zu erstellen... Die Suchergebnisse gehen erwartungsgemäß in eine ganz andere Richtung... :lol:

Ein kleiner Wink in die richtíge Richtung würde mir schon helfen. Ich würde das auch gerne direkt in phpBB realisieren und nicht mit den extra erstellten php-Dateien. Allerdings bin ich in dem Bereich noch nicht fit genug :-) Aber lernfähig :-)

Edit: Das mit den Berechtigungen für einzelne User kenne ich. Dieser Weg ist denkbar einfach. Allerdings muss ich den Dozenten dann ins ACP schicken. Das möchte ich verhindern.
Fügen Sie hier Ihre Signatur ein.
Benutzeravatar
canonknipser
Ehemaliges Teammitglied
Beiträge: 2053
Registriert: 10.09.2011 11:14
Kontaktdaten:

Re: User soll Gruppe und Forum erstellen dürfen

Beitrag von canonknipser »

Ich würde an deiner Stelle nicht die phpBB-Funktionen zum Erstellen von Gruppen etc. nachbauen, so wie du das machst, das geht mit Sicherheit irgend wann schief. Z.B. liegt auf der Gruppen-Tabelle in der Regel ein Autoincrement für die ID (wie für die anderen Tabellen auch) das ignorierst du und ermittelst mühsam in einer Schleife die nächste freie Group-ID:

Code: Alles auswählen

$sql = "SELECT * FROM phpbb_groups ORDER BY group_id DESC LIMIT 1";
    foreach ($pdo->query($sql) as $row) {
        $letzte_group_id = $row['group_id'];
    }
    $group_id = $letzte_group_id + 1;
Grundsätzlich solltest du auch das DBAL von phpBB nutzen.
Dazu musst du natürlich die entsprechenden Basisfunktionen in dein Script einbauen, also so in der art:

Code: Alles auswählen

<?php
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
// more includes ...

// Start session management
$user->session_begin();
$auth->acl($user->data);


 
die weiteren Includes, in denen deine zu rufenden Funktionen stecken, musst du natürlich auch mit einbinden.

Beispiele, wie ein Forum und die dazugehörigen Rechte angelegt werden, findest du in den acp-Modulen includes/acp/...
Grüße, canonknipser
"there are only 10 types of people: those, who understand binary and those, who don't"
just arrived ;) - Bilder
Kein Support via PN, nur im Board und (manchmal) im IRC
Benutzeravatar
Pofi
Mitglied
Beiträge: 252
Registriert: 06.10.2007 10:17
Wohnort: Wuppertal
Kontaktdaten:

Re: User soll Gruppe und Forum erstellen dürfen

Beitrag von Pofi »

Jetzt verstehe ich das ganze etwas besser :-)
Ist nicht so leicht, wenn man sich das alles selbst irgendwie beibringen muss ...

Also reicht es, acp_forums.php zu includen und das Formular entsprechend auf "add" zu stellen?!? Es gibt da ja auch noch diese Formtoken. Die erstellen sich automatisch?
Ich würde dann gerne das Formular aus dem ACP nutzen, wobei die meissten Einstellungen unter "hidden" laufen..

Aber zunächst erstmal vielen Dank... Das bringt mich schon etwas weiter...
Fügen Sie hier Ihre Signatur ein.
Benutzeravatar
gn#36
Ehrenadmin
Beiträge: 9313
Registriert: 01.10.2006 16:20
Wohnort: Ganz in der Nähe...
Kontaktdaten:

Re: User soll Gruppe und Forum erstellen dürfen

Beitrag von gn#36 »

Soweit vorhanden solltest du für alles API Funktionen in bestehendem phpBB Programmcode nutzen. In den meisten Fällen sparst du damit sehr viel Zeit. Leider gibt's noch nicht für alle Zwecke eine vernünftige API, ein Forum anzulegen passiert mit einer ziemlich alten Schnittstelle. Nichts desto trotz kannst du genau die mitbenutzen und profitierst dann auch von Updates an der Schnittstelle.

Hierzu schau dir einfach die includes/acp/acp_forums.php an. Mit der Methode update_forum_data können Foren geändert und angelegt werden, in der Methode main kannst du dir ansehen, welche Daten der Methode bereitgestellt werden bevor sie aufgerufen wird, mit der Methode delete_forum kannst du Foren löschen.

Sprich: Nachdem du deine Datei in den phpBB Kontext gelegt hast, ggf. ähnlich wie von canonknipser beschrieben würde ich dann obige Datei einbinden und mir ein Objekt von dieser Klasse anlegen mit dem man dann per $objekt->update_forum_data($parameter1, $parameter2) das gewünschte Forum anlegt.

Ähnlich sieht das aus mit Gruppenfunktionen, weil die bei weitem häufiger gebraucht werden gibt es hier aber eine bessere API, du musst nicht das ACP Modul entführen. Stattdessen gibt es die includes/functions_user.php, in der so ziemlich alles an Funktionen enthalten ist, was du so mit Gruppen und Usern anstellen kannst, inklusive Löschen und Anlegen von Gruppen und hinzufügen und entfernen von Usern zu diesen Gruppen. Auch da dann wieder: Deinen Code im phpBB Kontext ausführen, die Datei inkludieren und anschließend einfach die Funktionen aufrufen, die du gerade so brauchst.

Auf der nächsten Stufe kannst du das ganze dann gleich in eine phpBB Erweiterung gießen, irre viel fehlt hierzu eh nicht mehr:
KB:ext_erstellen
Begegnungen mit dem Chaos sind fast unvermeidlich, Aber nicht katastrophal, solange man den Durchblick behält.
Übertreiben sollte man's im Forum aber nicht mit dem Chaos, denn da sollen ja andere durchblicken und nicht nur man selbst.
Benutzeravatar
Pofi
Mitglied
Beiträge: 252
Registriert: 06.10.2007 10:17
Wohnort: Wuppertal
Kontaktdaten:

Re: User soll Gruppe und Forum erstellen dürfen

Beitrag von Pofi »

Ich habe das gerade erst gelesen :-) Vielen Dank für diese ausführliche Erklärung. :grin:

So langsam beginne ich das alles zu verstehen. Ich habe ursprünglich versucht das direkt in die SQL zu hämmern. Da aber noch weitere Parameter erforderlich sind, als ein paar Berechtigungen und der Gruppenname habe ich mir da einiges durcheinander gebracht :-)

Ich arbeite immer mehr mit den phpBB-eigenen Funktionen, was natürlich viel sinnvoller ist. Ihr beide habt mir sehr geholfen, vielen Dank. Der letzte Anstoß mit der Ext ist natürlich auch nicht schlecht. Da hätte ich dann alles in einem Verzeichnis und kann bei Problemen viel gezielter arbeiten. Wer weiß schon nach ein paar Jahren, welche Codezeilen er wo geändert hat :roll:
Fügen Sie hier Ihre Signatur ein.
Antworten

Zurück zu „Coding & Technik“