#!/usr/bin/perl # MimerDesk # Web based groupware and eLearning environment # www.mimerdesk.org # # Copyright (C) 2001 Ionstream Ltd. # www.ionstream.fi # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free # Software Foundation; either version 2 of the License, or (at your option) # any later version. # # This program is distributed with a hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License # for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # $Id: useredit.html,v 1.17 2002/07/14 09:07:24 inf Exp $ ########################################### # # # MimerDesk: Config - Edit users # # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # # (c) Ionstream Oy 1999 - 2001 # # # # Programmed by: Teemu Arina # # # ########################################### # Configuration ################################## use strict; use vars qw ($APPLICATION $ARTICLE $MONTH $USER $IP $LAST_ACT $FORWARDED $TIME_USED $IDLE $form $ref $sth $nopic $trans $profileref $picture $pic $htmlcolors $picurl $admin_status @months); use lib::MimerDesk; use CGI::Carp "fatalsToBrowser"; $APPLICATION = 'Tools - Users: Edit'; $picurl = '/userpics'; sub print_template; sub update; sub get_profile; # Program ################################## read_config('../config/mimerdesk.cfg'); $nopic = "$config{'loc_pictures'}/nopic.gif"; $htmlcolors = initialize('colors'); $form = decode_multipart(); $form->{'ID'} =~ tr/0-9//cd; $form->{'auth'} =~ tr/0-9a-z//cd; unlink($form->{'file-to-upload-1'}) if $form->{'file-to-upload-1'} ne '' && !$form->{'upload'}; ($USER, $IP, $LAST_ACT, $FORWARDED, $TIME_USED, $IDLE) = authenticate($form->{'ID'}, $form->{'auth'}); $trans = lib::MimerDesk->new_gettext(program => 'edit_users',language => $config{'language'}); $APPLICATION = $trans->gettext("Tools - Users: Edit"); @months = ( '', $trans->gettext('January'), $trans->gettext('February'), $trans->gettext('March'), $trans->gettext('April'), $trans->gettext('May'), $trans->gettext('June'), $trans->gettext('July'), $trans->gettext('August'), $trans->gettext('September'), $trans->gettext('October'), $trans->gettext('November'), $trans->gettext('December') ); lock_tables('READ', 'users'); db_list("SELECT * FROM users where nimi = '$USER'"); while (my $ref = $sth->fetchrow_hashref()) {$admin_status = $ref->{'flags'};} db_end(); unlock_tables(); print_template("$config{'theme'}_accfailure") if $admin_status !~ /U0/; $form->{'user'} = prepare_fordb($form->{'user'}); lock_tables('READ', 'users'); db_list("SELECT * FROM users where nimi = '$form->{'user'}'"); my $profileref = $sth->fetchrow_hashref(); db_end(); unlock_tables(); print_template("$config{'theme'}_wronguser") if !$profileref; if ($form->{'update'}) { update(); get_profile(); print_template("$config{'theme'}_edituser",'success',$trans->gettext('Saved changes.') ); } else { get_profile(); print_template("$config{'theme'}_edituser"); } # Aliohjelmat ################################## ############### # update user # ############### sub update { my (%specs,$phonenumber); lock_tables('READ', 'profileparts'); db_list("SELECT RECORD,NAME,PID FROM profileparts order by PID"); while (my $ref = $sth->fetchrow_hashref()) { if ($ref->{'NAME'} =~ /^phone(\d)$/) { $phonenumber = $1; $specs{$ref->{'RECORD'}} = qq[$form->{"phone${phonenumber}_menu"}|$form->{$ref->{'RECORD'}}]; } elsif ($ref->{'RECORD'} =~ /^age$/) { $form->{'age1'} =~ tr/0-9//cd; $form->{'age2'} =~ tr/0-9//cd; $form->{'age3'} =~ tr/0-9//cd; $specs{$ref->{'RECORD'}} = "$form->{'age1'}.$form->{'age2'}.$form->{'age3'}"; } else {$specs{$ref->{'RECORD'}} = $form->{$ref->{'RECORD'}};} if ($form->{"$ref->{'RECORD'}_visible"}) {$specs{'PROFILE'} .= $ref->{'PID'};} } db_end(); unlock_tables(); undef $specs{'flags'}; $specs{'flags'} .= "S0" if $form->{'sessions'}; $specs{'flags'} .= "N0" if $form->{'news'}; $specs{'flags'} .= "I0" if $form->{'config'}; $specs{'flags'} .= "L0" if $form->{'links'}; $specs{'flags'} .= "R0" if $form->{'reviews'}; $specs{'flags'} .= "M0" if $form->{'forums'}; $specs{'flags'} .= "C0" if $form->{'chat'}; $specs{'flags'} .= "G0" if $form->{'groups'}; $specs{'flags'} .= "U0" if $form->{'userman'}; $specs{'flags'} .= "P0" if $form->{'publicsite'}; $specs{'flags'} .= "V0" if $form->{'voting'}; $specs{'flags'} .= "T0" if $form->{'tv'}; # Matrikkeli if($form->{'matr'} == 1) {$specs{'flags'} .= "A0";} elsif($form->{'matr'} == 2) {$specs{'flags'} .= "A1";} # /Matrikkeli if ($form->{'expire'} eq 'never') { $specs{'expire'} = '-1'; } else { my $expmonth; foreach (@months) { $expmonth++; last if $form->{'expmonth'} eq $_; } $specs{'expire'} = local_date2utc_epoch(0,0,0,$form->{'expday'},$expmonth,$form->{'expyear'}); } foreach (keys %specs) {($specs{$_}) = prepare_fordb($specs{$_});} if (length($form->{'password_field'}) >= $config{'min_pass_length'}) { $specs{'password'} = crypt($form->{'password_field'}, 'aa'); } lock_tables('WRITE', 'users'); db_update('users',\%specs,"nimi='$form->{'user'}'"); unlock_tables(); lock_tables('READ', 'users'); db_list("SELECT * FROM users where nimi = '$form->{'user'}'"); $profileref = $sth->fetchrow_hashref(); db_end(); unlock_tables(); write_log("$USER changed profile of user $form->{'user'}!", 'notify'); } ################## # Print userinfo # ################## sub get_profile { opendir(DIR, "$config{'dir_userpics'}") or write_log("$USER: Error opening dir $config{'dir_userpics'}. $!", 'error'); foreach (readdir DIR) { next if /^\./; next if -d; if (/^($form->{'user'}\-.*)/) { $pic = $_; $picture = "$picurl/$_"; last; } } closedir DIR; $picture = $nopic if !$picture; } ############################ # Read template and print # ############################ sub print_template { my ($template,$ref,$fulltemplate,%dropvalues,$selected,@order,$password, $content,$date,$expires,$section,$checkbox,$lastvisit,$visitcount, $default,$paiva,$kuukausi,$vuosi,$flags); my ($template, $mode, $popuptext) = @_; print_header('pragma'); $ref = get_template($template,"$config{'theme'}_country"); my $countrydrop = $ref->{'default_country'}; $fulltemplate = $ref->{$template}; %dropvalues = ( 'work' => $trans->gettext('Work'), 'home' => $trans->gettext('Home'), 'other' => $trans->gettext('Other'), 'fax' => $trans->gettext('Fax'), 'mobile' => $trans->gettext('Mobile'), ); @order = qw(work home mobile fax other); $fulltemplate =~ s/<>/$mode/m; if ($popuptext) {$fulltemplate =~ s/<>/$popuptext

/m;} else {$fulltemplate =~ s/<>//m;} $fulltemplate =~ s/<>/minea/gm; $fulltemplate =~ s/<>/MimerDesk\: $APPLICATION/ms; $fulltemplate = replace_tags($fulltemplate, $USER, $form->{'auth'}, $form->{'ID'}, $TIME_USED); lock_tables('READ', 'users'); db_list("SELECT visitcount,lastpage,flags FROM users where nimi = '$form->{'user'}'"); while (my $ref = $sth->fetchrow_hashref()) { $visitcount = $ref->{'visitcount'}; $lastvisit = $ref->{'lastpage'}; $flags = $ref->{'flags'}; } db_end(); unlock_tables(); my $profile = starttable(width => '100%',align => 'center',cellspacing => 1,cellpadding => 1,gridcolor => 'black'). startrow(). column(bgcolor => "$htmlcolors->{'title'}", class => 'blackTitle', colspan => 2, content => " ". sprintf($trans->gettext('Edit user %s'), $form->{'user'}) ). endrow(); lock_tables('READ', 'profileparts'); db_list("SELECT * FROM profileparts where VISIBLE = 'Y' order by PID"); while (my $ref = $sth->fetchrow_hashref()) { if ($ref->{'NAME'} =~ /^phone(\d)$/) { my $phonenumber = $1; $profileref->{$ref->{'RECORD'}} =~ /^(\w+)\|(.*)$/; $selected = $1; $profileref->{$ref->{'RECORD'}} = $2; $section = dropdownmenu(name => "phone${phonenumber}_menu", order => \@order, default => $selected, values => \%dropvalues); } else {$section = " $ref->{'NAME'}";} if ($ref->{'RECORD'} eq 'age') { my ($age1,$age2,$age3) = (); $profileref->{$ref->{'RECORD'}} =~ /^(\d*).(\d*).(\d*)$/; if ($profileref->{$ref->{'RECORD'}}) { $age1 = $1; $age2 = $2; $age3 = $3; } $content = textfield(name => 'age1', value => $age1, size => 2, maxlength => 2).'.'. textfield(name => 'age2', value => $age2, size => 2, maxlength => 2).'.'. textfield(name => 'age3', value => $age3, size => 4, maxlength => 4); } elsif ($ref->{'RECORD'} eq 'country') { $countrydrop =~ s/(\=\"$profileref->{$ref->{'RECORD'}}\")/$1 selected/m; $content = $countrydrop; } else { $content = textfield(name => $ref->{'RECORD'}, value => $profileref->{$ref->{'RECORD'}}, size => 30, maxlength => $ref->{'SIZE'}); } $profile .= startrow(). column(class => 'content',bgcolor => "$htmlcolors->{'sectitle'}",content => $section). column(class => 'content',bgcolor => 'white',content => $content). endrow(); } db_end(); unlock_tables(); $content = textfield(name => 'password_field', size => 30, maxlength => 25); $profile .= startrow(). column(class => 'content',bgcolor => "$htmlcolors->{'sectitle'}",content => $trans->gettext('New password') ). column(class => 'content',bgcolor => 'white',content => $content). endrow(); $profile .= endtable('hasgrid'); $fulltemplate =~ s/<>/$profile/m; my ($sekunnit,$minuutit,$tunnit,$paiva,$kuukausi,$vuosi) = utc_epoch2date($profileref->{'date'}); $date = "$vuosi/$kuukausi/$paiva $tunnit:$minuutit:$sekunnit"; $fulltemplate =~ s/<>/$date/m; $fulltemplate =~ s/<>/$form->{'user'}/mg; $fulltemplate =~ s/<>/$picture/m; $fulltemplate =~ s/<>/$pic/m; if ($profileref->{'expire'} eq '-1') {$default = 'never';} else { (undef,undef,undef,$paiva,$kuukausi,$vuosi) = utc_epoch2date($profileref->{'expire'}); $expires = "$vuosi/$kuukausi/$paiva $tunnit:$minuutit:$sekunnit"; $default = $profileref->{'expire'}; } my $html = radiobuttons(name => 'expire', values => [$profileref->{'expire'}, 'never'], default => $default); $expires = $html->{$profileref->{'expire'}}. dropdownmenu(name => 'expday', order => [1..31], default => $paiva). dropdownmenu(name => 'expmonth', order => \@months, default => $months[$kuukausi-1]). dropdownmenu(name => 'expyear', order => [$vuosi-2..$vuosi+10], default => $vuosi). tag('br'). $html->{'never'}.$trans->gettext('Never'); $fulltemplate =~ s/<>/$expires/m; ($lastvisit,$IP) = split /\|/, $lastvisit; if (!$lastvisit) {$lastvisit = $trans->gettext('Never logged in.');} else { my ($sec,$min,$hour,$mday,$mon,$year) = utc_epoch2date($lastvisit); $lastvisit = "$year/$mon/$mday ".$trans->gettext('at')." $hour:$min:$sec ".$trans->gettext('from')." $IP"; } $fulltemplate =~ s/<>/$visitcount/m; $fulltemplate =~ s/<>/$lastvisit/m; $fulltemplate =~ s/\%\%sessionsselect\%\%/checked/m if $flags =~ /S0/; $fulltemplate =~ s/\%\%newsselect\%\%/checked/m if $flags =~ /N0/; $fulltemplate =~ s/\%\%configselect\%\%/checked/m if $flags =~ /I0/; $fulltemplate =~ s/\%\%linksselect\%\%/checked/m if $flags =~ /L0/; $fulltemplate =~ s/\%\%reviewsselect\%\%/checked/m if $flags =~ /R0/; $fulltemplate =~ s/\%\%forumsselect\%\%/checked/m if $flags =~ /M0/; $fulltemplate =~ s/\%\%chatselect\%\%/checked/m if $flags =~ /C0/; $fulltemplate =~ s/\%\%groupsselect\%\%/checked/m if $flags =~ /G0/; $fulltemplate =~ s/\%\%usermanselect\%\%/checked/m if $flags =~ /U0/; $fulltemplate =~ s/\%\%publicsiteselect\%\%/checked/m if $flags =~ /P0/; $fulltemplate =~ s/\%\%votingselect\%\%/checked/m if $flags =~ /V0/; $fulltemplate =~ s/\%\%tvselect\%\%/checked/m if $flags =~ /T0/; # Matrikkeli $fulltemplate =~ s/\%\%matrselectr\%\%/checked/m if $flags =~ /A1/; $fulltemplate =~ s/\%\%matrselectrw\%\%/checked/m if $flags =~ /A0/; $fulltemplate =~ s/\%\%matrselect\%\%/checked/m if $flags !~ /A[0-1]/; # /Matrikkeli $fulltemplate =~ s/\%\%[a-z]+\%\%//gm; print $fulltemplate; db_end('disconnect'); exit; }