philippK-de / Collabtive

Collabtive is web based project management software
https://collabtive.o-dyn.de
GNU General Public License v3.0
215 stars 131 forks source link

Role assignment problems #123

Closed Tomark closed 7 years ago

Tomark commented 8 years ago

I find some problems in changing the user's role, and correct them by modifying the method "assign" in the class "roles" (file: include/class.roles.php, at line 130 and following). Here's my version:

function assign($role, $user)
{
    global $conn;
    $role = (int) $role;
    $user = (int) $user;
    // get the number of roles already assigned to $user
    $chk = $conn->query("SELECT COUNT(*) FROM roles_assigned WHERE user = $user")->fetch();
    $chk = $chk[0];
    // If there already is a role assigned to the user, just update this entry
    // Otherwise create a new entry
    if ($chk > 0) {
        $insStmt = $conn->prepare("UPDATE roles_assigned SET role = ? WHERE user = ?");
    } else {
        $insStmt = $conn->prepare("INSERT INTO roles_assigned (role,user) VALUES (?,?)");
    }
    $ins = $insStmt->execute(array($role, $user));
    if ($ins) {
        return true;
    } else {
        return false;
    }
}
philippK-de commented 7 years ago

pls explain in more details & send pull request

evaK-de commented 7 years ago

Will be fixed in the next commit.