GetLuna / Luna

Luna is an easy and beautiful solution to build your own board.
http://getluna.org
GNU General Public License v2.0
81 stars 25 forks source link

No is possible define moderators #1725

Open crowleysbr opened 4 years ago

crowleysbr commented 4 years ago

Hello!

I can not define the users as Moderator in Luna. Yes, the user is in group of Moderators, but, in the forums and subforums, the functions of moderator no appears, and when he access the page by URL, the forum says "you not can access this page"!

In the file thread.php, exist this variable: <?php if ($is_admmod): ?>

Searching in the repository, this variable not exist or return 0 if user no is ADMIN.

crowleysbr commented 4 years ago

Hello.

if you want define the moderators by the "Forum Permissions" of forums and subforums, is necessary that alterate table in SQL. BACKUP first of all!

First, access the _forum_forumperms and click in SQL Query with this code: ALTER TABLE forum_forum_perms ADD COLUMN can_moderate int(1) NOT NULL DEFAULT 0;

Done? Ok, access the file functions.php in includes folder, and open the file. In last line, insert the function:

function getModeratorTools ($forum,$group) { global $luna_config, $db; $result = $db->query("SELECT * FROM {$db->prefix}forum_perms WHERE forum_id='{$forum}' AND group_id='{$group}'") or error('Unable to fetch user info', FILE, LINE, $db->error()); //if ($db->num_rows($result)>0) {return 'TRUE';} else {return 'FALSE';} if ($db->num_rows($result)>0) {return true;} else {return false;} } Explanation of the function: $forum = ID of forum that the user (or in this case, the group) can or not moderate. You can defined this in your Panel more later! $group = Number of group of the session actual. If the user is of group "22", for example, this function go search by permission of group in forum defined.

This function no change or cause crash in your forum. She call the resource if YOU call her.

Save your file "function.php" and, access the folder of your theme. This is, the theme that is applied in your forum (Fifteen or Sunrise). In this folder, open the file thread.php in folder views and find by: <?php if($is_admmod): ?> Replace by: <?php if(getModeratorTools($cur_thread['forum_id'],$luna_user['g_id']) OR $is_admmod): ?>

Ok. Now, you already configure the yours moderator permission. Remember that this resource is to forum permission, and that exist the function native for define the moderators. For me, is good like this, ok?

Access the backstage folder in root forum, and open the file "board.php". Find by: $result = $db->query('SELECT g.g_id, g.g_title, g.g_read_board, g.g_comment, g.g_create_threads, fp.read_forum, fp.comment, fp.create_threads FROM '.$db->prefix.'groups AS g LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (g.g_id=fp.group_id AND fp.forum_id='.$forum_id.') WHERE g.g_id!='.LUNA_ADMIN.' ORDER BY g.g_id') or error('Unable to fetch group forum permission list', __FILE__, __LINE__, $db->error());

I go explain this before of you change informations, ok? How you can define the moderators, you can create a column with the field of type checkbox. And this field is only for members that they are in group moderators (_you can see good, if you open your phpyadmin, in forumgroups) with name g_moderators = '1'.

Ok, let's go! You go create a new "TH" tag in table. After of: <th><?php _e('Create threads', 'luna') ?></th> Insert: <th><?php _e('Moderator', 'luna') ?></th>

And find by: <td<?php if (!$create_threads_def) echo ' class="danger"'; ?>> And insert after of closed tag TD. This that, inser new TD, ok?

                            <td<?php if (!$moderate_def) echo ' class="danger"'; ?>>
                               <input type="hidden" name="moderate_old[<?php echo $cur_perm['g_id'] ?>]" value="<?php echo ($moderate) ? '1' : '0'; ?>" />
                               <input type="checkbox" name="moderate_new[<?php echo $cur_perm['g_id'] ?>]" value="1"<?php echo ($moderate) ? ' checked' : ''; ?><?php echo ($cur_perm['g_moderator'] == '0') ? ' disabled="disabled"' : ''; ?> tabindex="<?php echo $cur_index++ ?>" />
                           </td>

Ok, if you save the file and acccess your panel, you can see the function, but, no work still. You can find by this: if (isset($_POST['read_forum_old'])) This is the action of PHP for posting your modifications about permissions. You need add new informations here for you "POST" send your permission of field moderate_new and moderate_old.

After of: $create_threads_new = isset($_POST['create_threads_new'][$cur_group['g_id']]) ? '1' : '0'; Insert: $moderate_new = isset($_POST['moderate_new'][$cur_group['g_id']]) ? '1' : '0';

Find by: || $create_threads_new != $_POST['create_threads_old'][$cur_group['g_id']] and insert it in same line after of cited, the new code: || $moderate_new != $_POST['moderate_old'][$cur_group['g_id']]

find by: $create_threads_new == $cur_group['g_create_threads'] and insert it in same line after of cited, the new code: && $moderate_new == $cur_group['g_moderator'] Nice work friend. almost there!

find by: , create_threads='.$create_threads_new.' and insert it in same line after of cited, the new code: , can_moderate='.$moderate_new.'

ufs! Now find by: $db->query('INSERT INTO '.$db->prefix.'forum_perms (group_id, forum_id, read_forum, comment, create_threads) VALUES('.$cur_group['g_id'].', '.$forum_id.', '.$read_forum_new.', '.$comment_new.', '.$create_threads_new.')') or error('Unable to insert group forum permissions', __FILE__, __LINE__, $db->error());

You can see that this code INSERT the permissions, right? So... You can add the "can_moderate" in list. The new code is: $db->query('INSERT INTO '.$db->prefix.'forum_perms (group_id, forum_id, read_forum, comment, create_threads, can_moderate) VALUES('.$cur_group['g_id'].', '.$forum_id.', '.$read_forum_new.', '.$comment_new.', '.$create_threads_new.', '.$moderate_new.')') or error('Unable to insert group forum permissions', __FILE__, __LINE__, $db->error());

Save, and you can see one subforum or forum in your panel and change the permission for your moderators group.