diff options
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/RHRD/rddb.pm | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/lib/RHRD/rddb.pm b/lib/RHRD/rddb.pm index a337557..f8832d1 100755 --- a/lib/RHRD/rddb.pm +++ b/lib/RHRD/rddb.pm @@ -534,6 +534,78 @@ sub set_group_reports return ($cnt, 'OK', "Success"); } +sub get_group_members +{ + my ($dbh, $groupname) = @_; + + my $sql = qq{select USER_NAME from USER_PERMS where GROUP_NAME = ?;}; + my $sth = $dbh->prepare($sql) + or return (undef, 'ERROR', "Database Error: " . $dbh->errstr); + + $sth->execute($groupname) + or return (undef, 'ERROR', "Database Error: " . $sth->errstr); + + my @users; + while(my ($user) = $sth->fetchrow_array()) { + push @users, $user; + } + $sth->finish(); + + return @users; +} + +sub is_group_member +{ + my ($dbh, $groupname, $username) = @_; + + my $sql = qq{select count(*) from USER_PERMS where GROUP_NAME = ? and USER_NAME = ?;}; + my $sth = $dbh->prepare($sql) + or return (undef, 'ERROR', "Database Error: " . $dbh->errstr); + + $sth->execute($groupname, $username) + or return (undef, 'ERROR', "Database Error: " . $sth->errstr); + + my ($cnt) = $sth->fetchrow_array(); + $sth->finish(); + + return ($cnt, 'OK', "success"); +} + +sub add_group_member +{ + my ($dbh, $groupname, $username) = @_; + + my ($cnt, $result, $errostring) = is_group_member($dbh, $groupname, $username); + if($cnt > 0) { + return (undef, 'ERROR', "already a member"); + } + + my $sql = qq{insert into USER_PERMS (GROUP_NAME, USER_NAME) values (?, ?);}; + my $sth = $dbh->prepare($sql) + or return (undef, 'ERROR', "Database Error: " . $dbh->errstr); + + $cnt = $sth->execute($groupname, $username) + or return (undef, 'ERROR', "Database Error: " . $sth->errstr); + + $sth->finish(); + return ($cnt, 'OK', "success"); +} + +sub remove_group_member +{ + my ($dbh, $groupname, $username) = @_; + + my $sql = qq{delete from USER_PERMS where GROUP_NAME = ? and USER_NAME = ?;}; + my $sth = $dbh->prepare($sql) + or return (undef, 'ERROR', "Database Error: " . $dbh->errstr); + + my $cnt = $sth->execute($groupname, $username) + or return (undef, 'ERROR', "Database Error: " . $sth->errstr); + + $sth->finish(); + return ($cnt, 'OK', "success"); +} + ########################### SHOW handling ########################### sub get_showtitle_and_log |