home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / FAQ / discus_admin_1357211388 / source / adm-grp.pl < prev    next >
Text File  |  2009-11-06  |  6KB  |  220 lines

  1. # FILE: adm-grp.pl
  2. # DESCRIPTION: Group Manager Interfaces
  3. #-------------------------------------------------------------------------------
  4. # DISCUS COPYRIGHT NOTICE
  5. #
  6. # Discus is copyright (c) 2002 by DiscusWare, LLC, all rights reserved.
  7. # The use of Discus is governed by the Discus License Agreement which is
  8. # available from the Discus WWW site at:
  9. #    http://www.discusware.com/discus/license
  10. #
  11. # Pursuant to the Discus License Agreement, this copyright notice may not be
  12. # removed or altered in any way.
  13. #-------------------------------------------------------------------------------
  14.  
  15. use strict;
  16. use vars qw($GLOBAL_OPTIONS $DCONF $PARAMS);
  17.  
  18. ###
  19. ### GROUP_admin
  20. ###
  21. ### Controls Group Manager and all of its functions
  22. ###
  23.  
  24. sub GROUP_admin {
  25.     my ($FORMref) = @_;
  26.     my $result = check_password($FORMref->{username}, undef, { type_required => 'moderator' }, $FORMref->{'COOKIE'});
  27.     bad_login( { bad_username => 1 } ) if scalar(@{ $result }) == 0;
  28.     bad_login( { superuser_required => 1 } ) if $result->[0]->{user} ne $DCONF->{superuser};
  29.     group_manager($FORMref, $result->[0]->{user}) if $FORMref->{action} eq "grp_mgr";
  30.     group_add($FORMref, $result->[0]->{user}) if $FORMref->{action} eq "grp_add";
  31.     if ($FORMref->{'action'} eq "grp_mgmt") {
  32.         my $sa = $FORMref->{SELECTION_action};
  33.         my $sw = $FORMref->{SELECTION_who};
  34.         if ($sa eq 'd') {
  35.             my $count = group_delete($sw, $FORMref->{MARK});
  36.             group_manager($FORMref, $result->[0]->{user}, { what => 2, count => $count });
  37.         } elsif ($sa eq 'e') {
  38.             group_edit_screen(($sw eq "*" ? $FORMref->{MARK} : $sw), $result->[0]->{user});
  39.         } else {
  40.             error_message("Group Management Error", "Error code GM001: Invalid Query", 0, 1);
  41.         }
  42.     }
  43.     if ($FORMref->{action} eq "grp_mod") {
  44.         group_edit_save($FORMref->{'affect'}, $FORMref->{'mod'});
  45.         group_edit_screen($FORMref->{'affect'}, $result->[0]->{user}, 2);
  46.     }
  47.     if ($FORMref->{action} eq "grp_notify") {
  48.         dreq("fcn-user-PRO");
  49.         my @m = ();
  50.         my %z = map { $_, 1 } split(/,/, $FORMref->{mod});
  51.         foreach my $u (split(/,/, $FORMref->{mod_choice})) {
  52.             my $emhash = {};
  53.             $emhash->{username} = $u;
  54.             $emhash->{action} = $z{$u} == 1 ? 'add_str' : 'rem_str';
  55.             $emhash->{new_str} = $FORMref->{affect};
  56.             push @m, $emhash;
  57.         }
  58.         new_registrations_email_moderators_config_write(\@m);
  59.         group_edit_screen($FORMref->{affect}, $result->[0]->{user}, 1);
  60.     }
  61. }
  62.  
  63. ###
  64. ### group_edit_save
  65. ###
  66. ### Saves group editing privileges of moderators
  67. ###
  68.  
  69. sub group_edit_save {
  70.     my ($groups, $moderators) = @_;
  71.     dreq("fcn-grp");
  72.     my @actions = ({ group => $groups, moderator => $moderators, action => 'set_equal' });
  73.     write_group_file(\@actions);
  74. }
  75.  
  76. ###
  77. ### group_edit_screen
  78. ###
  79. ### Screen where you select what moderators will belong to a group
  80. ###
  81.  
  82. sub group_edit_screen {
  83.     my ($groups, $username, $saved_flag) = @_;
  84.     dreq("fcn-grp");
  85.     my $group_cache = read_group_file();
  86.     my $mod = read_account_file("passwd", undef, { returnformat => 'single_array' });
  87.     my @mod = ();
  88.     my @gs = split(/,/, $groups);
  89.     foreach my $x (@{ $mod }) {
  90.         my $i = {};
  91.         $i->{user} = $x->{user};
  92.         $i->{name} = $x->{fullname};
  93.         my $c = 0;
  94.         foreach my $g (@gs) {
  95.             $c += check_group_authorization($x->{user}, $g, $group_cache);
  96.         }
  97.         $i->{checked} = ($c >= scalar(@gs) ? 1 : 0);
  98.         push (@mod, $i);
  99.     }
  100.     @mod = sort {
  101.         return 1 if $b->{user} eq $DCONF->{superuser};
  102.         return -1 if $a->{user} eq $DCONF->{superuser};
  103.         return lc($a->{user}) cmp lc($b->{user});
  104.     } @mod;
  105.     my $subst = {};
  106.     if ($DCONF->{pro} && scalar @gs == 1) {
  107.         dreq("selfreg-PRO", "fcn-user-PRO");
  108.         my $x = read_selfreg_file();
  109.         my $param = $x->{param}->{$gs[0]}->{param};
  110.         if ($param == 2) {
  111.             my $hash = new_registrations_email_moderators_config_read(0, $group_cache);
  112.             my $l = {};
  113.             foreach my $k (keys %{$hash}) {
  114.                 my $grps = $hash->{$k}->{groups};
  115.                 next if ! defined $grps->{$gs[0]};
  116.                 $l->{$k} = 1;
  117.             }
  118.             foreach my $z (@mod) {
  119.                 $z->{notify_checked} = 0 + $l->{$z->{user}};
  120.             }
  121.             $subst->{general}->{groupmail} = 1;
  122.         }
  123.     }
  124.     $subst->{moderators} = \@mod;
  125.     $subst->{general}->{mods} = scalar(split(/,/, $groups));
  126.     $subst->{general}->{group} = $groups;
  127.     $subst->{general}->{username} = $username;
  128.     $subst->{general}->{affect} = $groups;
  129.     $subst->{general}->{saved_flag} = $saved_flag;
  130.     screen_out("grpmodas", $subst);
  131. }
  132.  
  133. ###
  134. ### group_manager
  135. ###
  136. ### Main interface of the Group Manager screen
  137. ###
  138.  
  139. sub group_manager {
  140.     my ($FORMref, $username, $stuff) = @_;
  141.     dreq("fcn-grp");
  142.     my $group_file = read_group_file(1);
  143.     my @groups = ();
  144.     foreach my $g (@{ $group_file->{group_list} }) {
  145.         next if $g eq "#" || $g !~ m|\S|;
  146.         my $i = {};
  147.         $i->{group_name} = $g;
  148.         $i->{mod_count} = scalar(keys(%{ $group_file->{by_grp}->{$g} }));
  149.         push (@groups, $i);
  150.     }
  151.     @groups = sort { lc($a->{group_name}) cmp lc($b->{group_name}) } @groups;
  152.     my $subst = {};
  153.     $subst->{'general'}->{'url'} = "$PARAMS->{cgiurl}?action=grp_mgr&username=$username";
  154.     $subst->{'general'}->{'menu'} = $FORMref->{'menu'};
  155.     $subst->{'general'}->{'username'} = $username;
  156.     $subst->{'groups'} = \@groups;
  157.     $subst->{'stuff'} = $stuff;
  158.     screen_out("groupmgr", $subst);
  159. }
  160.  
  161. ###
  162. ### group_add
  163. ###
  164. ### Adds a group
  165. ###
  166.  
  167. sub group_add {
  168.     my ($FORMref, $username) = @_;
  169.     undef my $subst;
  170.     $subst->{'general'}->{'url'} = "$PARAMS->{cgiurl}?action=grp_mgr&username=$username";
  171.     $subst->{'general'}->{'menu'} = 1;
  172.     $subst->{'general'}->{'username'} = $username;
  173.     my $y = prepare_userpass($FORMref->{group});
  174.     $y =~ s/\W//g;
  175.     if (length($y) < 1 || length($y) > 15) {
  176.         error_message("Add Group Error", "Group name must be 1-15 characters long.  Only alphanumeric characters (A-Z, 0-9, underscore) are allowed.", 0, 1);
  177.     }
  178.     dreq("fcn-grp");
  179.     my $ctr = write_group_file([ { group => $y, action => "add_group" } ]);
  180.     if ($ctr == 0) {
  181.         error_message("Add Group Error", "New group could not be added.  Make sure group name does not already exist.", 0, 1);
  182.     }
  183.     $subst->{stuff}->{what} = 1;
  184.     $subst->{stuff}->{group_added} = $y;
  185.     header();
  186.     print templ_int("groupmgr", $subst);
  187.     program_exit(0);
  188. }
  189.  
  190. ###
  191. ### group_delete
  192. ###
  193. ### Deletes a group
  194. ###
  195.  
  196. sub group_delete {
  197.     my ($delete, $mark) = @_;
  198.     dreq("fcn-grp");
  199.     my @del = ();
  200.     if ($delete eq "*") {
  201.         @del = split(/,/, $mark);
  202.     } else {
  203.         @del = ($delete);
  204.     }
  205.     if ($DCONF->{pro}) {
  206.         dreq("selfreg-PRO");
  207.         selfreg_delete_groups(\@del);
  208.     }
  209.     my @d = ();
  210.     foreach my $i (@del) {
  211.         undef my $u;
  212.         $u->{group} = $i;
  213.         $u->{action} = "del_group";
  214.         push (@d, $u);
  215.     }
  216.     return write_group_file(\@d);
  217. }
  218.  
  219. 1;
  220.