#!/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: profile.html,v 1.42 2002/07/14 09:07:24 inf Exp $ ########################################### # # # MimerDesk: Config - profile # # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # # (c) Ionstream Oy 1999 - 2001 # # # # Programmed by: Teemu Arina # # # ########################################### # Todo: # # - Remove some globals # Configuration ################################## use strict; use vars qw ($APPLICATION $ACTIVEGRP $ARTICLE $MONTH $USER $IP $LAST_ACT $FORWARDED $TIME_USED $IDLE $form $ref $sth $nopic @LANGUAGES $profileref $picture $pic $htmlcolors $gettext); use lib::MimerDesk; use CGI::Carp "fatalsToBrowser"; $APPLICATION = 'Config - Profile'; sub print_template; sub upload_pic; sub update; sub get_profile; sub delete_pic; # Program ################################## read_config('../config/mimerdesk.cfg'); push @LANGUAGES, $_ foreach sort { $LANGUAGES{$a} cmp $LANGUAGES{$b} } keys %LANGUAGES; $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'}; lock_tables('READ', 'configuration'); unlock_tables(); ($USER, $IP, $LAST_ACT, $FORWARDED, $TIME_USED, $IDLE, $ACTIVEGRP) = authenticate($form->{'ID'}, $form->{'auth'}, $form->{'changeGroup'}); $gettext = lib::MimerDesk->new_gettext(program => 'profile',language => $config{'language'}); $APPLICATION = $gettext->gettext('Config - Profile'); if ($form->{'quit'}) {redirect("$config{'loc_server'}$config{'bin_dir'}/index.html?ID=$form->{'ID'}&auth=$form->{'auth'}&quit=quit");} elsif ($form->{'update'}) { unlink($form->{'file-to-upload-1'}); update(); get_profile(); print_template("$config{'theme'}_profile",'success','Saved changes.'); } elsif ($form->{'deletepic'}) { unlink($form->{'file-to-upload-1'}); delete_pic(); update(); get_profile(); print_template("$config{'theme'}_profile",'success','Your picture has been successfully deleted from the server.'); } elsif ($form->{'upload'} && $form->{'file-to-upload-1'} ne '') { upload_pic(); update(); get_profile(); print_template("$config{'theme'}_profile", 'success','Your picture has been successfully uploaded to the server.'); } else { unlink($form->{'file-to-upload-1'}); get_profile(); print_template("$config{'theme'}_profile"); } # Aliohjelmat ################################## ################## # Upload picture # ################## sub upload_pic { delete_pic(); my $prefix = $form->{'file-to-upload-1' , 'tiedostonimi'}; $prefix =~ s/(.*)\.(.*)$/$2/; $prefix =~ s/\n//; $prefix = lc $prefix; if ($prefix =~ /jpg/ || $prefix =~ /gif/ || $prefix =~ /png/) { rename $form->{'file-to-upload-1'}, "$config{'dir_userpics'}/$USER.$prefix"; } else {unlink($form->{'file-to-upload-1'});} } ################## # Delete picture # ################## sub delete_pic { 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 (/^$USER\./) { unlink("$config{'dir_userpics'}/$_"); last; } } closedir DIR; } ############### # update user # ############### sub update { my (%specs,$phonenumber); lock_tables('READ', 'profileparts'); db_list("SELECT RECORD,NAME,PID FROM profileparts where VISIBLE = 'Y' and EDITABLE = 'Y' 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(); if ($form->{'timezone'} =~ /^\-?\d+\.?\d*$/) { $specs{'timezone'} = $form->{'timezone'}; $config{'timezone'} = $form->{'timezone'}; } if ($form->{'language'} =~ /^[a-z][a-z]$/) { $specs{'language'} = $form->{'language'}; foreach ($config{'loc_pictures'},$config{'loc_pictures2'}, $config{'dir_pictures'},$config{'dir_pictures2'}) { s/([^\/]*)$//; $_ .= $form->{'language'}; } $config{'language'} = $form->{'language'}; } $gettext = lib::MimerDesk->new_gettext(program => 'profile',language => $config{'language'}); foreach (keys %specs) {($specs{$_}) = prepare_fordb($specs{$_});} lock_tables('WRITE', 'users'); db_update('users',\%specs,"nimi='$USER'"); unlock_tables(); write_log("$USER changed his/her profile!", 'notify'); } ################## # Print userinfo # ################## sub get_profile { lock_tables('READ', 'users'); db_list("SELECT * FROM users where nimi = '$USER'"); $profileref = $sth->fetchrow_hashref(); db_end(); unlock_tables(); 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 (/^$USER\./) { $pic = $_; $picture = "$config{'loc_userpics'}/$_"; last; } } closedir DIR; if (!$picture) {$picture = $nopic;} } ############################ # Read template and print # ############################ sub print_template { my ($template,$ref,$fulltemplate,%dropvalues,$selected,@order,$content,$date, $expires,$section,$checkbox,$lastvisit,$visitcount,$language); my ($template, $mode, $popuptext) = @_; print_header('pragma'); $ref = get_template('maintemplate',$template); $ref->{'maintemplate'} =~ s/<>/$ref->{$template}/m; $fulltemplate = $ref->{'maintemplate'}; $ref = get_template('js_doClock', 'js_help', 'js_profile', 'js_gotosite',"$config{'theme'}_country"); my $countrydrop = $ref->{'default_country'}; my $stuff = join "", ($ref->{'js_doClock'},$ref->{'js_help'},$ref->{'js_profile'},$ref->{'js_gotosite'}); if ($popuptext) {$popuptext = $gettext->gettext($popuptext);} %dropvalues = ( 'work' => $gettext->gettext('Work'), 'home' => $gettext->gettext('Home'), 'other' => $gettext->gettext('Other'), 'fax' => $gettext->gettext('Fax'), 'mobile' => $gettext->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/<>/$stuff/ms; $fulltemplate = create_buttons($fulltemplate, 'Config', 'Profile', $form); $fulltemplate =~ s/<>/minea/gm; $fulltemplate =~ s/<>/MimerDesk\: $APPLICATION/ms; $fulltemplate =~ s/