Code Duplication    Length = 7-8 lines in 4 locations

main/permissions/permissions_functions.inc.php 4 locations

@@ 96-102 (lines=7) @@
93
    }
94
95
    // grating a right
96
    if ($action == 'grant') {
97
        $sql = "INSERT INTO $table (c_id, $id_field,tool,action) VALUES ($course_id, '".Database::escape_string($id)."','".Database::escape_string($tool)."','".Database::escape_string($permission)."')";
98
        $result = Database::query($sql);
99
        if ($result) {
100
            $result_message = get_lang('PermissionGranted');
101
        }
102
    }
103
    if ($action == 'revoke') {
104
        $sql = "DELETE FROM $table WHERE c_id = $course_id AND $id_field = '".Database::escape_string($id)."' AND tool='".Database::escape_string($tool)."' AND action='".Database::escape_string($permission)."'";
105
        $result = Database::query($sql);
@@ 103-110 (lines=8) @@
100
            $result_message = get_lang('PermissionGranted');
101
        }
102
    }
103
    if ($action == 'revoke') {
104
        $sql = "DELETE FROM $table WHERE c_id = $course_id AND $id_field = '".Database::escape_string($id)."' AND tool='".Database::escape_string($tool)."' AND action='".Database::escape_string($permission)."'";
105
        $result = Database::query($sql);
106
        if ($result) {
107
            $result_message = get_lang('PermissionRevoked');
108
        }
109
    }
110
111
    return $result_message;
112
}
113
@@ 544-550 (lines=7) @@
541
    }
542
543
    // grating a right
544
    if ($action == 'grant') {
545
        $sql = "INSERT INTO $table (c_id, role_id, scope, $id_field) VALUES ($course_id, '".Database::escape_string($role_id)."','".Database::escape_string($scope)."','".Database::escape_string($id)."')";
546
        $result = Database::query($sql);
547
        if ($result) {
548
            $result_message = get_lang('RoleGranted');
549
        }
550
    }
551
552
    if ($action == 'revoke') {
553
        $sql = "DELETE FROM $table WHERE c_id = $course_id AND $id_field = '".Database::escape_string($id)."' AND role_id='".Database::escape_string($role_id)."'";
@@ 552-558 (lines=7) @@
549
        }
550
    }
551
552
    if ($action == 'revoke') {
553
        $sql = "DELETE FROM $table WHERE c_id = $course_id AND $id_field = '".Database::escape_string($id)."' AND role_id='".Database::escape_string($role_id)."'";
554
        $result = Database::query($sql);
555
        if ($result) {
556
            $result_message = get_lang('RoleRevoked');
557
        }
558
    }
559
    return $result_message;
560
}
561