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-user.pl < prev    next >
Text File  |  2009-11-06  |  20KB  |  552 lines

  1. # FILE: adm-user.pl
  2. # DESCRIPTION: Administration functions dealing with user management
  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. ### USER_admin
  20. ###
  21. ### Controls all User Manager functions
  22. ###
  23.  
  24. sub USER_admin {
  25.     my ($FORMref) = @_;
  26.     my $result = check_password($FORMref->{username}, undef, { type_required => 'moderator' }, $FORMref->{'COOKIE'});
  27.     my $stuff = {};
  28.     bad_login({ username => 1 }) if ! scalar(@{ $result });
  29.     dreq("fcn-grp");
  30.     user_mgr_1($FORMref) if $FORMref->{action} eq "user_mgr_1";
  31.     check_group_authorization($FORMref->{username}, $FORMref->{group}) || bad_login({ group_privilege => 1 });
  32.     if ($FORMref->{action} eq "user_copy") {
  33.         if ($FORMref->{newgroup} ne "") {
  34.             check_group_authorization($FORMref->{username}, $FORMref->{newgroup}) || bad_login({ group_privilege => 1 });
  35.             dreq("fcn-acct");
  36.             $stuff = user_copy(quotemeta($FORMref->{group}), quotemeta($FORMref->{newgroup}), $FORMref->{users}, $FORMref->{move});
  37.             $FORMref->{menu} = 0 if $FORMref->{users} ne "*";
  38.         } else {
  39.             $stuff->{failed_copy} = 1;
  40.         }
  41.         $FORMref->{action} = "user_mgr_2";
  42.     }
  43.     user_form_handler($FORMref, $result) if $FORMref->{SELECTION_action} ne "";
  44.     if ($FORMref->{action} eq "user_mgr_2" && $FORMref->{group} eq " ") {
  45.         bad_login( { superuser_required => 1 } ) if $result->[0]->{user} ne $DCONF->{superuser};
  46.         user_mgr_no_group($FORMref, $result, $stuff);
  47.     }
  48.     user_mgr_2($FORMref, $result, $stuff) if $FORMref->{action} eq "user_mgr_2";
  49.     user_self_reg_save($FORMref, $result) if $FORMref->{action} eq "user_selfreg";
  50.     if ($FORMref->{action} eq "user_edit_save") {
  51.         my $r = user_edit_save_someone_else($FORMref, $result);
  52.         user_edit_someone_else($FORMref, $result, undef, undef, {editsave => 1}, $r);
  53.     }
  54.     if ($FORMref->{action} eq "user_promote" && $result->[0]->{user} eq $DCONF->{superuser}) {
  55.         my %x = map { $_, 1 } grep { /\S/ } split(/,/, $FORMref->{mod});
  56.         dreq("promote-PRO");
  57.         promote_user_manager_action(\%x, $FORMref, $result);
  58.     }
  59.     if ($FORMref->{action} eq "user_mgr_suspend" && $DCONF->{pro}) {
  60.         dreq("suspend-PRO"); user_manager_suspend_action($FORMref, $result);
  61.     }
  62.     if ($FORMref->{action} =~ /user_list_/) {
  63.         dreq("usr-list"); userlist_admin_main($FORMref, $result);
  64.     }
  65.     user_manager_user_add($FORMref, $result) if $FORMref->{action} eq "um-add_user";
  66.  
  67. }
  68.  
  69. ###
  70. ### user_manager_user_add
  71. ###
  72. ### Adds a single user through the User Manager
  73. ###
  74.  
  75. sub user_manager_user_add {
  76.     my ($FORMref, $result) = @_;
  77.     dreq("fcn-acct", "authpass");
  78.     my $ah = {};
  79.     $ah->{user} = $FORMref->{newuser};
  80.     $ah->{pass1} = prepare_userpass_p($FORMref->{pass_1});
  81.     $ah->{pass2} = prepare_userpass_p($FORMref->{pass_2});
  82.     error_message("Add User Error", "The passwords in the "Password:" and "Retype Password:" boxes did not match.  When you use your browser's back button, re-enter the passwords so they do match.", 0, 1) if $ah->{pass1} ne $ah->{pass2};
  83.     $ah->{email} = $FORMref->{email};
  84.     $ah->{fullname} = $FORMref->{fullname};
  85.     $ah->{groups} = "/$FORMref->{group}/";
  86.     $ah->{forcechange} = 1 if $FORMref->{forcechange};
  87.     my ($success, $failure) = add_account($ah, { database => "users" });
  88.     if (ref $failure eq 'ARRAY' && scalar @{$failure} == 1 && $DCONF->{'pro'}) {
  89.         if ($failure->[0]->{'error_code'} == 1) {
  90.             dreq("userfilt-PRO");
  91.             my $code = username_conflict_resolver($ah->{'user'}, $ah->{'pass1'}, $FORMref->{'username'}, $ah->{'groups'});
  92.             if ($code == 1) {
  93.                 $success = \@{$failure};
  94.                 $failure = [];
  95.             }
  96.         }
  97.     }    
  98.     if (! scalar(@{ $success })) {
  99.         my $errcode = undef;
  100.         $errcode = $failure->[0]->{error_code} if $failure->[0]->{error_code};
  101.         $errcode = $failure->[0]->{FAILURE} if $failure->[0]->{FAILURE};
  102.         error_message("Add User Error", "The username \U$ah->{user}\E is already taken.", 0, 1) if $errcode == 1;
  103.         error_message("Add User Error", "The username \U$ah->{user}\E must be between 1 and 100 characters.", 0, 1) if $errcode == 2;
  104.         error_message("Add User Error", "The two passwords you entered did not match.", 0, 1) if $errcode == 3;
  105.         error_message("Add User Error", "You did not specify a password for this account.", 0, 1) if $errcode == 4;
  106.         if (defined $failure->[0]->{FAILURE_MESSAGE}) {
  107.             error_message("Add User Error", $failure->[0]->{FAILURE_MESSAGE}, 0, 1);
  108.         }
  109.         error_message("Add User Error", "Other error ($errcode)", 0, 1);
  110.     }
  111.     if ($FORMref->{emailpw} && $DCONF->{pro}) {
  112.         dreq("fcn-user-PRO");
  113.         user_mail_passwords($success, undef);
  114.     }
  115.     user_mgr_2($FORMref, $result, { added => "\U$success->[0]->{user}\E" });
  116. }
  117.  
  118. ###
  119. ### user_mgr_1
  120. ###
  121. ### First page of the User Manager interface.  Displays the groups and the
  122. ### user count, and you click which group you want to edit.
  123. ###
  124.  
  125. sub user_mgr_1 {
  126.     my ($FORMref) = @_;
  127.     my $groupfile = read_group_file();
  128.     my ($gr, $bad) = user_mgr_get_auth_groups($FORMref->{username}, $groupfile, undef, 1);
  129.     my @w = sort {$a->{group} cmp $b->{group}} @{$gr};
  130.     my $subst = {};
  131.     $subst->{general}->{username} = $FORMref->{username};
  132.     $subst->{grp_arr} = \@w;
  133.     $subst->{general}->{tot_grp} = scalar(keys %{$groupfile->{by_grp}});
  134.     if ($DCONF->{pro}) {
  135.         dreq("selfreg-PRO");
  136.         $subst->{queue} = count_queued_users($FORMref->{username});
  137.     }
  138.     if (ref $bad eq 'ARRAY' && scalar @{$bad} > 0) {
  139.         $subst->{general}->{nocount} = scalar @{$bad};
  140.     }
  141.     screen_out("usermgr1", $subst);
  142. }
  143.  
  144. ###
  145. ### user_mgr_2
  146. ###
  147. ### Second page of the User Manager -- the main script behind the display of
  148. ### the main User Manager interface.
  149. ###
  150.  
  151. sub user_mgr_2 {
  152.     my ($FORMref, $result, $stuff) = @_;
  153.     my $subst = {};
  154.     $subst->{general}->{url} = "$PARAMS->{cgiurl}?action=user_mgr_2&username=$result->[0]->{user}&group=$FORMref->{group}";
  155.     $subst->{general}->{menu} = $FORMref->{menu};
  156.     ($subst->{authgroups}) = user_mgr_get_auth_groups($result->[0]->{user});
  157.     $subst->{general}->{group} = $FORMref->{group};
  158.     $subst->{general}->{username} = $result->[0]->{user};
  159.     $subst->{general}->{users} = $subst->{authgroups}->[0]->{usrcnt};
  160.     if ($FORMref->{menu} == 4 && $DCONF->{pro}) {
  161.         dreq("selfreg-PRO", "webtags", "fcn-user-PRO");
  162.         my $r = read_selfreg_file();
  163.         my $g = $FORMref->{group};
  164.         $subst->{general}->{param} = $r->{param}->{$g}->{param};
  165.         $subst->{general}->{groupname} = inverse_webtags($r->{param}->{$g}->{groupname});
  166.         $subst->{general}->{descr} = inverse_webtags($r->{param}->{$g}->{descr});
  167.         $subst->{general}->{defcheck} = $r->{param}->{$g}->{defcheck};
  168.         my $x = new_registrations_email_moderators_config_read();
  169.         $subst->{notify}->{here} = $x->{$result->[0]->{user}}->{groups}->{$g};
  170.     } elsif ($FORMref->{menu} == 1) {
  171.         dreq("fcn-acct"); $subst->{general}->{randpass} = pick_random_password(1);
  172.     } elsif ($FORMref->{menu} == 0) {
  173.         my $results_per_screen = 25;
  174.         my $u = read_account_file("users", undef, { condition => { group => { group => $FORMref->{group}} }, returnformat => 'single_array' });
  175.         dreq("userfilt-PRO") if $DCONF->{pro};
  176.         if (! $FORMref->{clear}) {
  177.             $FORMref->{"l10"} = defined $FORMref->{"f10"} ? $FORMref->{"l10"} : 1;
  178.         } else {
  179.             $FORMref->{"l10"} = 1;
  180.             $FORMref->{"f10"} = 1;
  181.         }
  182.         foreach my $f (keys(%{ $FORMref })) {
  183.             if ($f =~ m|^l(\d+)|) {
  184.                 if ($FORMref->{clear} == 1 && $1 ne "10") {
  185.                     $FORMref->{"l$1"} = undef;
  186.                     $FORMref->{"f$1"} = undef;
  187.                 }
  188.                 $subst->{filter}->{"l$1"} = $FORMref->{"l$1"};
  189.                 $subst->{filter}->{"f$1"} = $FORMref->{"f$1"};
  190.             }
  191.         }
  192.         $subst->{general}->{size_u} = 0;
  193.         my @u = (); my $grp = quotemeta($FORMref->{group});
  194.         foreach my $us (@{ $u }) {
  195.             $subst->{general}->{size_u}++;
  196.             next if ($DCONF->{pro} && is_user_filtered_pro($FORMref, $us));
  197.             next if (! $DCONF->{pro} && is_user_filtered_freeware($FORMref, $us));
  198.             if ($us->{pass} =~ m%^\*.*?\|\|\*\*$%) {
  199.                 $us->{suspend_ban} = 1;
  200.             } elsif ($us->{pass} =~ m%^\*.*\|\|\*$%) {
  201.                 $us->{suspend_cancel} = 1;
  202.             } elsif ($us->{pass} =~ m%^\*.*\|\|\*Q$%) {
  203.                 $us->{suspend_queue} = 1;
  204.             } elsif ($us->{pass} =~ m%^\*.*\|\|\*\%%) {
  205.                 $us->{suspend_acceptance} = 1;
  206.             } elsif ($us->{pass} =~ m%^\*.*\|\|\*\!%) {
  207.                 $us->{suspend_pwchange} = 1;
  208.             } elsif ($us->{pass} =~ m%^\*.*\|\|%) {
  209.                 $us->{suspend_email} = 1;
  210.             }
  211.             $us->{suspend} = 1 if $us->{pass} =~ m%^\*%;
  212.             $us->{ctime} = "0" if $us->{ctime} =~ /\D/;
  213.             $us->{atime} = "0" if $us->{atime} =~ /\D/;
  214.             $us->{stime} = "0" if $us->{stime} =~ /\D/;
  215.             push (@u, $us);
  216.         }
  217.         @u = sort {
  218.             return 1 if $a->{user} gt $b->{user};
  219.             return -1 if $a->{user} lt $b->{user};
  220.             return 0;
  221.         } @u;
  222.         my $c = 0;
  223.         my @l = ();
  224.         foreach my $ue (@u) {
  225.             $ue->{ident} = ++$c;
  226.             push @l, $ue->{user};
  227.         }
  228.         $subst->{general}->{mark_all_string} = join(",", @l);
  229.         $subst->{general}->{match} = scalar(@u);
  230.         if (scalar(@u) > $results_per_screen) {
  231.             $subst->{general}->{s} = $FORMref->{s};
  232.             my $s = 0 + $FORMref->{s};
  233.             my @t = ();
  234.             for (my $i = 0; $i < scalar(@u); $i += $results_per_screen) {
  235.                 my $o = {};
  236.                 $o->{firstuser} = $u[$i]->{user};
  237.                 my $luid = ($i + $results_per_screen) > scalar(@u) ? scalar(@u) : ($i + $results_per_screen);
  238.                 $o->{lastuser} = $u[$luid-1]->{user};
  239.                 $o->{ident} = 1+$i;
  240.                 push @t, $o;
  241.             }
  242.             $s = 1 if ($s < 1 || $s != int($s) || $s > scalar(@u));
  243.             my @z = ();
  244.             if ($FORMref->{s} eq "*") {
  245.                 @z = @u;
  246.             } else {
  247.                 my @u2 = @u;
  248.                 @z = splice @u2, $s-1, $results_per_screen;
  249.                 undef @u2;
  250.             }
  251.             $subst->{users} = \@z;
  252.             $subst->{t} = \@t;
  253.             $subst->{first_user} = $z[0];
  254.             $subst->{last_user} = $z[$#z];
  255.             $subst->{general}->{result_per_page} = $results_per_screen;
  256.             $subst->{general}->{screen_up} = $s - $results_per_screen;
  257.             $subst->{general}->{screen_up} = 1 if $subst->{general}->{screen_up} <= 1;
  258.             $subst->{general}->{screen_down} = $s + $results_per_screen;
  259.             $subst->{general}->{screen_down} = $s if $subst->{general}->{screen_down} > scalar(@u);
  260.             $subst->{general}->{screen_last} = 1+$results_per_screen * int(($u[$#u]->{ident}-1) / $results_per_screen);
  261.         } else {
  262.             $subst->{users} = \@u;
  263.         }
  264.     }
  265.     $subst->{stuff} = $stuff;
  266.     screen_out("usermgr2", $subst);
  267. }
  268.  
  269. ###
  270. ### user_mgr_get_auth_groups
  271. ###
  272. ### Returns the groups a moderator is permitted to edit
  273. ###
  274.  
  275. sub user_mgr_get_auth_groups {
  276.     my ($moderator, $groupfile, $groupmatch, $count) = @_;
  277.     $groupfile = read_group_file() if ! defined $groupfile;
  278.     my @garr = ();
  279.     my @bad = ();
  280.     my $groupcount = {};
  281.     if ($count) {
  282.         my $ct = 0;
  283.         if ($DCONF->{pro} && $GLOBAL_OPTIONS->{database}) {
  284.             dreq("sql-acct-PRO");
  285.             ($groupcount, $ct) = sql_count_users($moderator);
  286.         } else {
  287.             my $rg = read_account_file("users", undef, { return_fields => { user => 1, groups => 1, pass => 1 }, returnformat => "single_array" });
  288.             foreach my $u (@{ $rg }) {
  289.                 my @g = grep { /\S/ } split(/\//, $u->{groups});
  290.                 if (scalar @g == 0 && $moderator eq $DCONF->{superuser}) {
  291.                     push @bad, $u;
  292.                 } else {
  293.                     foreach my $l (@g) {
  294.                         $groupcount->{$l} += 1;
  295.                     }
  296.                 }
  297.                 $ct++;
  298.             }
  299.         }
  300.         dreq("fcn-acct");
  301.         update_registered_users_file($ct);
  302.     }
  303.     foreach my $q (@{ $groupfile->{group_list} }) {
  304.         if ($moderator ne $DCONF->{superuser}) {
  305.             next if ! check_group_authorization($moderator, $q, $groupfile);
  306.         }
  307.         my $r = {};
  308.         $r->{group} = $q;
  309.         $r->{usrcnt} = 0 + $groupcount->{$q};
  310.         push (@garr, $r) if (! defined $groupmatch || $groupmatch eq "" || $groupmatch eq $q);
  311.     }
  312.     return (\@garr, \@bad);
  313. }
  314.  
  315. ###
  316. ### is_user_filtered_freeware
  317. ###
  318. ### Basic filtering for user list (Discus Pro contains a more advanced
  319. ### filter in addition to this one).
  320. ###
  321.  
  322. sub is_user_filtered_freeware {
  323.     my ($FORMref, $userref) = @_;
  324.     return 1 if is_user_filtered_compare(1, "user", $FORMref, $userref);
  325.     return 1 if is_user_filtered_compare(2, "email", $FORMref, $userref);
  326.     return 1 if is_user_filtered_compare(3, "fullname", $FORMref, $userref);
  327.     return 0;
  328. }
  329.  
  330. ###
  331. ### is_user_filtered_compare
  332. ###
  333. ### Compares a given field
  334. ###
  335.  
  336. sub is_user_filtered_compare {
  337.     my ($number, $reference, $FORMref, $userref) = @_;
  338.     my $fn = "f$number"; my $ln = "l$number";
  339.     return 0 if $FORMref->{$ln} eq "";
  340.     my $q = quotemeta(trim($FORMref->{$ln}));
  341.     return 1 if $FORMref->{$fn} == 1 && $userref->{$reference} !~ m|$q|i;
  342.     return 1 if $FORMref->{$fn} == 2 && $userref->{$reference} =~ m|$q|i;
  343.     return 1 if $FORMref->{$fn} == 7 && $userref->{$reference} !~ m|^$q$|i;
  344.     return 0;
  345. }
  346.  
  347. ###
  348. ### user_self_reg_save
  349. ###
  350. ### Saves user self-registration settings
  351. ###
  352.  
  353. sub user_self_reg_save {
  354.     my ($FORMref, $result) = @_;
  355.     dreq("selfreg-PRO", "webtags", "fcn-user-PRO");
  356.     user_mgr_save_settings($FORMref, $result);
  357.     user_mgr_2($FORMref, $result, { selfreg => 1 });
  358. }
  359.  
  360. ###
  361. ### user_form_handler
  362. ###
  363. ### Handles delete, copy, edit clicks from User Manager
  364. ###
  365.  
  366. sub user_form_handler {
  367.     my ($FORMref, $result) = @_;
  368.     my $w = {};
  369.     if ($FORMref->{SELECTION_who} eq "*") {
  370.         my $j = $FORMref->{markall} == 1 ? $FORMref->{MARKALL} : $FORMref->{MARK};
  371.         foreach my $l (split(/\,/, $j)) {
  372.             $w->{$l} = 1;
  373.         }
  374.     } else {
  375.         $w->{$FORMref->{SELECTION_who}} = 1;
  376.     }
  377.     if ($FORMref->{SELECTION_action} eq "d") { ## Delete user(s)
  378.         dreq("fcn-acct");
  379.         return delete_account($w, undef, "users");
  380.     }
  381.     if ($FORMref->{SELECTION_action} eq "r") { ## Remove user(s) from group
  382.         dreq("fcn-acct");
  383.         return remove_account_group($w, undef, "users", $FORMref->{group});
  384.     }
  385.     if ($FORMref->{SELECTION_action} eq "s") { ## Suspend user(s)
  386.         dreq("suspend-PRO");
  387.         user_manager_suspend($FORMref, $result, $w);
  388.     }
  389.     if ($FORMref->{SELECTION_action} eq "e") { ## Edit user
  390.         user_edit_someone_else($FORMref, $result, $w, undef);
  391.     }
  392.     if ($FORMref->{SELECTION_action} eq "u") { ## Promote user to moderator
  393.         dreq("promote-PRO");
  394.         promote_user_manager($w, $FORMref, $result);
  395.     }
  396.     if ($FORMref->{SELECTION_action} =~ /^[cm]$/) { ## Copy/move user
  397.         my $subst = {};
  398.         $subst->{general}->{username} = $result->[0]->{user};
  399.         $subst->{general}->{menu} = 3;
  400.         $subst->{general}->{move} = 1 if $FORMref->{SELECTION_action} eq "m";
  401.         $subst->{general}->{users} = join(",", keys(%{$w}));
  402.         $subst->{general}->{group} = $FORMref->{group};
  403.         ($subst->{authgroups}) = user_mgr_get_auth_groups($result->[0]->{user});
  404.         $subst->{general}->{url} = "$PARAMS->{cgiurl}?action=user_mgr_2&username=$result->[0]->{user}&group=$FORMref->{group}";
  405.         $subst->{general}->{skip_menu} = 1;
  406.         $subst->{general}->{show_copy} = 1;
  407.         screen_out("usermgr2", $subst, undef);
  408.     }
  409.     if ($FORMref->{SELECTION_action} eq "l") { ## Create a mailing list
  410.         dreq("authpass");
  411.         my $Z = read_account_file("users", $w, { returnformat => "single_array" });
  412.         my %f = map { $_->{email}, 1 } @{$Z};
  413.         my $subst = {};
  414.         my @z = map { { email => $_ } } sort keys %f;
  415.         $subst->{addresses} = \@z;
  416.         screen_out("emlist", $subst);
  417.     }
  418. }
  419.  
  420. ###
  421. ### user_edit_save_someone_else
  422. ###
  423. ### Saves changes you make to someone else's profile
  424. ###
  425.  
  426. sub user_edit_save_someone_else {
  427.     my ($FORMref, $result, $database) = @_;
  428.     $database = "users" if $database eq "";
  429.     dreq("fcn-acct", "ui-prfle");
  430.     my $s = {};
  431.     $s->{user} = $FORMref->{user};
  432.     $s->{fullname} = $GLOBAL_OPTIONS->{name_length_limit} ? substr($FORMref->{fullname}, 0, $GLOBAL_OPTIONS->{name_length_limit_number}) : $FORMref->{fullname};
  433.     if ($FORMref->{new_pass_1} ne "") {
  434.         my ($pw1, $pw2) = prepare_userpass_p($FORMref->{new_pass_1}, $FORMref->{new_pass_2});
  435.         if ($pw1 ne $pw2 || length($pw1) < 1) {
  436.             error_message(read_language()->{PROFILE_CHPASS_ERROR}, read_language()->{PROFILE_CHPASS_ERROR_MATCH});
  437.         }
  438.         $s->{new_password} = $pw1;
  439.     }
  440.     $s->{email} = trim($FORMref->{email});
  441.     $s->{edit} = $FORMref->{edit_true_false};
  442.     if ($FORMref->{email_included} == 1) {
  443.         my $h = {}; my $rr = {};
  444.         my @r = split(/,/, $FORMref->{bysub});
  445.         foreach my $_r (@r) {
  446.             if ($_r =~ m|^(\d+):(.*)|) {
  447.                 my ($topic, $splits) = ($1, $2);
  448.                 my @sp = split(/&/, $splits);
  449.                 foreach my $sp (@sp) {
  450.                     $rr->{$topic}->{$sp} = 1;
  451.                 }
  452.             }
  453.         }
  454.         my @s = split(/,/, $FORMref->{notify});
  455.         foreach my $s (@s) {
  456.             if ($s =~ m|^0+$|) {
  457.                 $h->{own_post} = 1 if $s eq "0";
  458.                 $h->{reply_post} = 1 if $s eq "00";
  459.                 $h->{format_html} = 1 if $s eq "000";
  460.             } elsif (defined $rr->{$s}) {
  461.                 $h->{$s} = $rr->{$s};
  462.             } else {
  463.                 $h->{$s}->{'*'} = 1 if ! defined $rr->{$s};
  464.             }
  465.         }
  466.         if ($DCONF->{pro}) {
  467. #            dreq("fcn-prfl-PRO");
  468. #            ($h) = notification_simple_prune($h, $FORMref, undef, $result);
  469.         }
  470.         $s->{notify} = email_notification_hash_to_line($h);
  471.     }
  472.     if (defined $FORMref->{cmonth}) {
  473.         my $k = eval '
  474.             use Time::Local;
  475.             my $x = timelocal(0,0,12,$FORMref->{cday},$FORMref->{cmonth},$FORMref->{cyear});
  476.             $x;
  477.         ';
  478.         if ($@ eq "" && $k > 0) {
  479.             $s->{ctime} = $k;
  480.         }
  481.     }
  482.     my ($success, $failure) = update_account($s, $database, undef);
  483.     if ($DCONF->{pro} && scalar(@{$success})) {
  484.         dreq("fcn-prfl-PRO");
  485.         my $mt = $database eq "passwd" ? 10 : 8;
  486.         $mt = 10 if $result->[0]->{user} eq $DCONF->{superuser};
  487.         my $q = {};
  488.         $q->{status} = $FORMref->{status} if $FORMref->{status} >= 3 && $FORMref->{status} <= $mt;
  489.         $q->{posts} = $FORMref->{posts} if $FORMref->{posts} >= 0;
  490.         enhanced_profile_update($FORMref, $success->[0], $q);
  491.     }
  492.     my $r = undef;
  493.     $r = $success->[0] if ref $success eq "ARRAY" && ref $success->[0] eq "HASH";
  494.     return [$r];
  495. }
  496.  
  497. ###
  498. ### user_edit_someone_else
  499. ###
  500. ### Edit someone else's user (or moderator) account
  501. ###
  502.  
  503. sub user_edit_someone_else {
  504.     my ($FORMref, $result, $w, $subst_in, $stuff, $res, $file) = @_;
  505.     dreq("authpass", "template", "ui-prfle");
  506.     $file = "users" if $file eq "";
  507.     $res = read_account_file($file, $w, { returnformat => 'single_array'}) if ! defined $res;
  508.     my $subst = defined $subst_in ? $subst_in : {};
  509.     error_message("Edit User Error", "The selected user does not exist.", 0, 1) if ref $res ne 'ARRAY';
  510.     my $h = $res->[0];
  511.     my @m = ();
  512.     $subst->{messages} = \@m;
  513.     $subst->{general}->{spell_checking_enabled} = (-e "$DCONF->{admin_dir}/msg_index/wordlist.txt") * $GLOBAL_OPTIONS->{spell_check};
  514.     $subst->{stuff} = $stuff;
  515.     my $current = undef;
  516.     if ($DCONF->{pro}) {
  517.         dreq("fcn-prfl-PRO", "authwrap-PRO");
  518.         ($subst) = profile_editor_variables($subst, $FORMref, undef, $current, $h, $result, $FORMref->{username});
  519.     } else {
  520.         ($subst) = profile_editor_email_notification_freeware($subst, $FORMref, undef, $current, $h);
  521.     }
  522.     $subst->{general}->{group} = $FORMref->{group};
  523.     $subst->{general}->{editing} = $file eq "passwd" ? 2 : 1;
  524.     $subst->{general}->{self} = $result->[0]->{user};
  525.     $subst->{general}->{username} = $h->{user};
  526.     $subst->{general}->{action} = $file eq "passwd" ? "mod_edit_save" : "user_edit_save";
  527.     $subst->{general}->{action_url} = $PARAMS->{cgiurl};
  528.     $subst->{ffield}->{fullname} = $h->{fullname};
  529.     $subst->{ffield}->{email} = $h->{email};
  530.     $subst->{ffield}->{edit} = $h->{edit};
  531.     $subst->{general}->{skip_top_options_bar} = 1;
  532.     $subst->{general}->{skip_no_frames_buttons} = 1;
  533.     if ($GLOBAL_OPTIONS->{email}) {
  534.         if ($GLOBAL_OPTIONS->{send_mail_only_admins} == 0) {
  535.             $subst->{general}->{email_notification} = 1;
  536.         } else {
  537.             foreach my $r (@{ $result }) {
  538.                 $subst->{general}->{email_notification} = 1 if $r->{database} eq "passwd";
  539.             }
  540.         }
  541.     }
  542.     my @l = localtime($h->{ctime} + $GLOBAL_OPTIONS->{'timezone'}*3600);
  543.     $subst->{creation}->{month} = $l[4];
  544.     $subst->{creation}->{day} = $l[3];
  545.     $subst->{creation}->{year} = 1900 + $l[5];
  546.     $subst->{creation}->{curryear} = 1900 + (localtime(time))[5];
  547.     return $subst if defined $subst_in;
  548.     screen_out("profile", $subst);
  549. }
  550.  
  551. 1;
  552.