#!/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_view.html,v 1.11 2002/07/02 17:53:49 inf Exp $ #"""""""""""""""""""""""""""""""""""""""""# # # # MimerDesk: Profile view/friend list # # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # # (c) Ionstream Oy 1999 - 2001 # # # # Programmed by: Hannes Muurinen # # # #_________________________________________# use lib::MimerDesk; use strict; use vars qw($form $APPLICATION $USER $IP $LAST_ACT $FORWARDED $TIME_USED $IDLE $ACTIVEGRP $colors $actionmessage $profileref $picture $pic $nopic $default_forced_visible $number_of_columns $trans); use CGI::Carp "fatalsToBrowser"; sub print_template; sub get_userpics; $APPLICATION = 'Resources - User Profiles'; read_config('../config/mimerdesk.cfg'); $nopic = image(src => "$config{'loc_pictures'}/nopic.gif"); $config{'theme'} = 'default'; $default_forced_visible = 'A'; $number_of_columns = 3; #number of columns in the user list # The main program ################### $colors = initialize('colors'); $form = decode_multipart(); $form->{'ID'} =~ tr/0-9//cd; $form->{'auth'} =~ tr/0-9a-z//cd; $form->{'sort'} = 'info' if $form->{'sort'} eq ''; ($USER, $IP, $LAST_ACT, $FORWARDED, $TIME_USED, $IDLE, $ACTIVEGRP) = authenticate($form->{'ID'}, $form->{'auth'}, $form->{'changeGroup'}); if(lc($form->{'sort'}) eq 'password') { write_log("User $USER tried to sort the users according to their passwords in profile viewer!",'warning'); $form->{'sort'} = 'info'; } $trans = lib::MimerDesk->new_gettext(program => 'profile_view',language => $config{'language'}); $APPLICATION = $trans->gettext('Resources - User Profiles'); #get error/success messages: $actionmessage .= add_friend() if($form->{'addtofriends'} and $form->{'showprofile'}); $actionmessage .= remove_friend() if($form->{'removefromfriends'} and $form->{'showprofile'}); if($form->{'showprofile'}) {print_template("$config{'theme'}_profile_view");} else {print_template("$config{'theme'}_profile_list");} # Subs: ########### # print_template # # sub print_template { my ($template, $ref, $fulltemplate, $calendar, $navigation_right, $calinfo, $navigation_left); $template = shift; print_header('pragma'); $ref = get_template('maintemplate',$template); $ref->{'maintemplate'} =~ s/<>/$ref->{$template}/m; $fulltemplate = $ref->{'maintemplate'}; $fulltemplate = create_buttons($fulltemplate, 'Resources', 'User Profiles', $form); $fulltemplate =~ s/<>/minea/gm; $ref = get_template('js_doClock', 'js_help', 'js_gotosite'); my $stuff = $ref->{'js_doClock'}.$ref->{'js_help'}.$ref->{'js_gotosite'}; $fulltemplate =~ s/<>/$stuff/ms; $fulltemplate =~ s/<>/MimerDesk\: $APPLICATION/ms; if($form->{'showprofile'}) {$fulltemplate = replace_profileview_tags($fulltemplate);} else {$fulltemplate = replace_profilelist_tags($fulltemplate);} $fulltemplate =~ s/<>/$actionmessage/; $fulltemplate = replace_tags($fulltemplate, $USER, $form->{'auth'}, $form->{'ID'}, $TIME_USED); $fulltemplate = add_popups($fulltemplate, $USER, $form->{'auth'}, $form->{'ID'}); print $fulltemplate; db_end('disconnect'); exit; } ################################################################################# # replace_profileview_tags - replaces the tags in the template # #-------------------------------------------------------------------------------# # replace_profileview_tags($HTML_template) # # # # other arguments are read from the form # # # # Usage: # # $HTML_template = replace_profileview_tags($HTML_template) # # # ################################################################################# sub replace_profileview_tags { my $the_template = shift; my ($section, $content); get_profile(); $the_template =~ s/<>/$form->{'showprofile'}/msg; my $profile = starttable(width => '80%',align => 'center',cellspacing => 1,cellpadding => 2,gridcolor => 'black'). startrow(bgcolor => "$colors->{'title'}"). column(class => 'blackTitle',colspan => 2,content => ' ' . sprintf($trans->gettext('Profile for user %s'), $form->{'showprofile'})). 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+)\|(.*)$/; $section = ' ' . $trans->gettext(ucfirst($1)); $profileref->{$ref->{'RECORD'}} = $2; } else {$section = ' '.$ref->{'NAME'};} $content = " $profileref->{$ref->{'RECORD'}}"; $profile .= startrow(). column(class => 'content',width => 135,bgcolor => "$colors->{'sectitle'}",content => $section). column(class => 'content',bgcolor => '#FFFFFF',content => $content). endrow() if ($profileref->{'PROFILE'} =~ /$ref->{'PID'}/ or $default_forced_visible =~ /$ref->{'PID'}/); } db_end(); unlock_tables(); $profile .= endtable('hasgrid'); $the_template =~ s/<>/$profile/m; $the_template =~ s/<>/$picture/m; $the_template =~ s/<>/$pic/m; my ($buttonpicture, $buttontext, $buttonaction); lock_tables('READ', 'friends'); db_list("SELECT friend FROM friends where user = '$USER' and friend = '$form->{'showprofile'}'"); my $friendsref = $sth->fetchrow_hashref(); db_end(); unlock_tables(); if($friendsref->{'friend'}) { $buttonpicture = 'removefrommyfriends.gif'; $buttontext = $trans->gettext('Remove this user from your friend list'); $buttonaction = '&removefromfriends=true'; } else { $buttonpicture = 'addtomyfriends.gif'; $buttontext = $trans->gettext('Add this user to your friend list'); $buttonaction = '&addtofriends=true'; } my $buttonstuff = tagged('a',{href => "profile_view.html?ID=$form->{'ID'}&auth=$form->{'auth'}&showprofile=$form->{'showprofile'}$buttonaction", onMouseOver => 'doClock(); return true', content => image(src => "<>$buttonpicture", border => "0", alt => $buttontext)}) .'  '. tagged('a',{href => "friends.html?ID=$form->{'ID'}&auth=$form->{'auth'}", onMouseOver => 'doClock(); return true', content => image(src => "<>myfriends.gif", border => "0", alt => $trans->gettext('Show My Friends list'))}).'  '. tagged('a',{href => "javascript:popItMsg('reply=$form->{'showprofile'}',430,400,'$form->{'showprofile'}_msg')", onMouseOver => 'doClock(); return true', content => image(src => "<>sendamessage.gif", border => "0", alt => $trans->gettext('Send a short message'))}); $buttonstuff .= '  ' . tagged('a',{href => "profile.html?ID=$form->{'ID'}&auth=$form->{'auth'}",content => image(src => "<>editmyprofile.gif", border => "0", alt => $trans->gettext('Edit my profile'))}) if $form->{'showprofile'} eq $USER; #check user rights: lock_tables('READ', 'users'); db_list("SELECT flags FROM users where nimi = '$USER'"); my $flagsref = $sth->fetchrow_hashref(); db_end(); unlock_tables(); $buttonstuff .= '  ' . tagged('a',{href => "javascript:popUpEdit('ID=$form->{'ID'}&auth=$form->{'auth'}&user=$form->{'showprofile'}', 800, 600, '$form->{'showprofile'}')",content => image(src => "<>edituserprofile.gif", border => "0", alt => $trans->gettext('Edit profile of this user'))}) if $flagsref->{'flags'} =~ /U0/; $the_template =~ s/<>/$buttonstuff/m; return $the_template; } ##################### # Get userpics list # ##################### sub get_userpics { my @userpics; opendir(DIR, "$config{'dir_userpics'}") or write_log("$USER: Error opening dir $config{'dir_userpics'}. $!", 'error'); foreach (readdir DIR) { next if /^\./; next if -d; /^(.*)\./; push @userpics, $1; } closedir DIR; return @userpics; } ################################################################################# # replace_profilelist_tags - replaces the tags in the template # #-------------------------------------------------------------------------------# # replace_profilelist_tags($HTML_template) # # # # other arguments are read from the form # # # # Usage: # # $HTML_template = replace_profilelist_tags($HTML_template) # # # ################################################################################# sub replace_profilelist_tags { my $the_template = shift; my (%user_list, $user_table, $add_portrait); my $sort; if (lc($form->{'sort'}) eq 'info' or lc($form->{'sort'}) eq 'nimi') {$sort = $form->{'sort'};} else {$sort = 'info';} my @userpics = get_userpics(); lock_tables('READ', 'users'); db_list("SELECT nimi,info FROM users order by $sort"); while (my $ref = $sth->fetchrow_hashref()) { my ($firsttext, $secondtext); if($form->{'sort'} eq 'nimi') {($firsttext, $secondtext) = ($ref->{'nimi'}, "$ref->{'info'}");} else { ($firsttext, $secondtext) = ("$ref->{'info'}",$ref->{'nimi'}); } uc($ref->{$form->{'sort'}}) =~ /^(.)/; # get the first letter $add_portrait = undef; $add_portrait = " ".image(src => "$config{'loc_pictures'}\/portrait.gif") if (grep {$_ eq $ref->{'nimi'}} @userpics); push @{$user_list{$1}}, tagged('a',{href=> "profile_view.html?ID=$form->{'ID'}&auth=$form->{'auth'}&showprofile=$ref->{'nimi'}", onMouseOver => 'doClock(); return true', class => 'contentLink', content => "$firsttext - $secondtext".$add_portrait}); } db_end(); unlock_tables(); foreach my $userarrayname (sort (keys %user_list)) { # add the first letter: my $bigletter = $userarrayname; $bigletter = '#' if $bigletter =~ /^\s*$/; $user_table .= startrow(bgcolor => $colors->{'sectitle'}, align => 'left'). column(class => 'blackTitleBig', content => " $bigletter"). endrow(); # colspan => $number_of_columns, my $users_in_one_column = int((@{$user_list{$userarrayname}}-1) / $number_of_columns)+1; $user_table .= startrow(bgcolor => '#FFFFFF', align => 'left') . tag('td') . starttable(width => '100%', border => '0', cellspacing => '0', cellpadding => '0', bgcolor => '#FFFFFF', align => 'center') . startrow() . tag('td'); for (my $column=0; $column<$number_of_columns; $column++) { my ($firstindex, $lastindex) = ($column*$users_in_one_column , ($column+1)*$users_in_one_column); $firstindex = @{$user_list{$userarrayname}} if $firstindex > @{$user_list{$userarrayname}}; $lastindex = @{$user_list{$userarrayname}} if $lastindex > @{$user_list{$userarrayname}}; $user_table .= tag('td',{width => int(100 / $number_of_columns).'%', class => 'content', valign => 'top', align => 'left'}) . starttable(width => '100%', cellspacing => '1'); $user_table .= startrow(bgcolor => '#FFFFFF', align => 'left'). column(class => 'content', content => ' '). endrow(); for (my $row=$firstindex;$row<$lastindex;$row++) { $user_table .= startrow(bgcolor => '#FFFFFF', align => 'left'). column(class => 'content', content => ${$user_list{$userarrayname}}[$row]). endrow(); } $user_table .= endtable() .' ' . endtag('td'); } $user_table .= endtag('td') . endrow() . endtable() . endtag('td') . endrow(); } $the_template =~ s/<>/$user_table/m; my ($sortinfo, $sortname); if (lc($sort) eq 'nimi') { $sortinfo = tagged('a', {href=> "profile_view.html?ID=$form->{'ID'}&auth=$form->{'auth'}&sort=info", onMouseOver => 'doClock(); return true', class => 'grayTitleLink', content => $trans->gettext('name')}); $sortname = tagged('span', {class => 'blackTitleLink', content => $trans->gettext('username')}); } else { $sortinfo = tagged('span', {class => 'blackTitleLink', content => $trans->gettext('name')}); $sortname = tagged('a', {href=> "profile_view.html?ID=$form->{'ID'}&auth=$form->{'auth'}&sort=nimi", onMouseOver => 'doClock(); return true', class => 'grayTitleLink', content => $trans->gettext('username')}); } $the_template =~ s/<>/$sortinfo/msg; $the_template =~ s/<>/$sortname/msg; return $the_template; } ################## # Database fetch # ################## sub get_profile { lock_tables('READ', 'users'); db_list("SELECT * FROM users where nimi = '$form->{'showprofile'}'"); $profileref = $sth->fetchrow_hashref(); db_end(); unlock_tables(); my $username = $form->{'showprofile'}; 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 (/^$username\./) { $pic = $_; $picture = image(src => "$config{'loc_userpics'}/$_"); last; } } closedir DIR; if (!$picture) {$picture = $nopic;} } ################################################################################# # add_friend - adds current shown profile to the friend list # #-------------------------------------------------------------------------------# # add_friend() # # # # other arguments are read from the form # # # # Usage: # # $return_message = add_friend() # # # ################################################################################# sub add_friend { lock_tables('READ', 'users', 'friends'); db_list("SELECT nimi FROM users where nimi = '$form->{'showprofile'}'"); my $nameref = $sth->fetchrow_hashref(); db_end(); db_list("SELECT friend FROM friends where user = '$USER' and friend = '$form->{'showprofile'}'"); my $friendsref = $sth->fetchrow_hashref(); db_end(); unlock_tables(); return '
' . sprintf($trans->gettext('User %s isn\'t a MimerDesk user!'),$form->{'showprofile'}) .'
' if(!$nameref->{'nimi'}); return '
' . sprintf($trans->gettext('User %s is already in your friend list!'),$form->{'showprofile'}) .'
' if($friendsref->{'friend'}); lock_tables('WRITE', 'friends'); db_insert('friends',{user => $USER, friend => $nameref->{'nimi'}}); db_end(); unlock_tables(); return '
' . sprintf($trans->gettext('User %s was added to your friend list'),$form->{'showprofile'}) . '
'; } ################################################################################# # remove_friend - removes currently shown user to the friend list # #-------------------------------------------------------------------------------# # remove_friend() # # # # other arguments are read from the form # # # # Usage: # # $return_message = remove_friend() # # # ################################################################################# sub remove_friend { lock_tables('READ', 'users', 'friends'); db_list("SELECT nimi FROM users where nimi = '$form->{'showprofile'}'"); my $nameref = $sth->fetchrow_hashref(); db_end(); db_list("SELECT friend FROM friends where user = '$USER' and friend = '$form->{'showprofile'}'"); my $friendsref = $sth->fetchrow_hashref(); db_end(); unlock_tables(); return '
' . sprintf($trans->gettext('User %s isn\'t a MimerDesk user!'),$form->{'showprofile'}) .'
' if(!$nameref->{'nimi'}); return '
' . sprintf($trans->gettext('User %s is not in your friend list!'),$form->{'showprofile'}) .'
' if(!$friendsref->{'friend'}); lock_tables('WRITE', 'friends'); db_delete('friends',"user = '$USER' and friend = '$form->{'showprofile'}'"); db_end(); unlock_tables(); return '
' . sprintf($trans->gettext('User %s was removed from your friend list'),$form->{'showprofile'}) . '
'; }