Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sends PMs to indvidual users when set to groups. #137

Open
Rhababo opened this issue Oct 28, 2023 · 1 comment
Open

Sends PMs to indvidual users when set to groups. #137

Rhababo opened this issue Oct 28, 2023 · 1 comment
Labels

Comments

@Rhababo
Copy link

Rhababo commented Oct 28, 2023

Describe the bug
When using a form that sends PM's to groups, It sends multiple individual PM's to each member of the group, rather than a single PM with multiple recipients. This flags the messages as pm flooding and prevents all but one of the messages from going through.

To Reproduce
Steps to reproduce the behavior:

  1. Create a form that is set to send PM's to user groups with multiple users in the group.
  2. Have a non-admin (Registered) user fill out and send the form.
  3. See error

Expected behavior
When sending to a group, it should be sent as a single PM instead of several individual PM's.

Desktop (please complete the following information):
MyBB version: 1.8.36
Plugin version: 2.6.6
PHP version: 8.1.16
MySQL version: 5.7

I corrected this issue by changing the "get_usergroup_users" function in plugins/formcreator.php to only return an array of recipient userid's.

function get_usergroup_users_uid($gid)
{
    global $db;

    if (is_array($gid)) {
        $additionwhere = "";
        foreach ($gid as $groupid) {
            $additionwhere .= " OR CONCAT(',',additionalgroups,',') LIKE '%," . intval($groupid) . ",%'";
        }

        $query = $db->simple_select("users", "uid", "usergroup IN (" . implode(",", $gid) . ")" . $additionwhere);
    } else {
        $query = $db->simple_select("users", "uid", "usergroup IN (" . intval($gid) . ") OR CONCAT(',',additionalgroups,',') LIKE '%," . intval($gid) . ",%'");
    }

    if ($db->num_rows($query)) {
        $rownum = 0;
        while ($user = $db->fetch_array($query)) {
            $userarray[$rownum] = $user['uid'];
            $rownum++;
        }
        return $userarray;
    } else {
        return false;
    }
}

(This function is only called in form.php when sending PM's to groups)

once get_usergroup_users returns an array of receipients uids, then you can just set that as the "toid" value in the $pm array at line 260 (or so) in form.php

 $group_members = get_usergroup_users_uid($formcreator->settings['pmgroups']);
                        
                        $pmhandler = new PMDataHandler();

                        $pm = array(
                            "subject" => $subject,
                            "message" => $message,
                            "icon" => $formcreator->settings['posticon'],
                            "toid" => $group_members,
                            "fromid" => $uid,
                            "do" => '',
                            "pmid" => ''
                        );

This solution worked for me, but I haven't tested it fully with other configurations

@Rhababo Rhababo added the bug label Oct 28, 2023
@burnacid
Copy link
Owner

Thanks, I'll setup some tests to check. Feel free to create a pull request of this if you like

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants