#!/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: friends.html,v 1.9 2002/08/01 16:36:05 inf Exp $ #"""""""""""""""""""""""""""""""""""""""""# # # # MimerDesk: 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 $trans); use CGI::Carp "fatalsToBrowser"; sub print_template; $APPLICATION = 'Personal - Friends'; read_config('../config/mimerdesk.cfg'); $config{'theme'} = 'default'; # 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($form->{'sort'} ne 'info' || $form->{'sort'} ne 'nimi') {$form->{'sort'} = 'info';} $trans = lib::MimerDesk->new_gettext(program => 'friends',language => $config{'language'}); $APPLICATION = $trans->gettext('Personal - Friends'); #get error/success messages: $actionmessage .= remove_friend() if($form->{'remove_friend'}); print_template("$config{'theme'}_friends"); # Subs: ########### # print_template # # sub print_template { my ($template, $ref, $fulltemplate); $template = shift; print_header('pragma'); $ref = get_template('maintemplate',$template); $ref->{'maintemplate'} =~ s/<>/$ref->{$template}/m; $fulltemplate = $ref->{'maintemplate'}; $fulltemplate = create_buttons($fulltemplate, 'Personal', 'My Friends', $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; $fulltemplate = replace_friendlist_tags($fulltemplate); $fulltemplate =~ s/<>/$actionmessage/; $fulltemplate =~ s/<>/$form->{'grouptool'}/; $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_friendlist_tags - replaces the tags in the template # #-------------------------------------------------------------------------------# # replace_friendlist_tags($HTML_template) # # # # other arguments are read from the form # # # # Usage: # # $HTML_template = replace_friendlist_tags($HTML_template) # # # ################################################################################# sub replace_friendlist_tags { my $the_template = shift; my ($friendlist); my $number_of_checkboxes = 0; lock_tables('READ', 'users', 'friends'); db_list("SELECT users.nimi,users.info FROM users,friends where friends.user = '$USER' and friends.friend = users.nimi order by users.".prepare_fordb($form->{'sort'})); while (my $ref = $sth->fetchrow_hashref()) { $friendlist .= startrow(class=> 'content', bgcolor => '#FFFFFF') . column(content => ' '. tagged('a',{href => "profile_view.html?ID=$form->{'ID'}&auth=$form->{'auth'}&showprofile=$ref->{'nimi'}", onMouseOver => 'doClock(); return true', class => 'content', content => $ref->{'info'}})). column(content => ' '. tagged('a',{href => "profile_view.html?ID=$form->{'ID'}&auth=$form->{'auth'}&showprofile=$ref->{'nimi'}", onMouseOver => 'doClock(); return true', class => 'content', content => $ref->{'nimi'}})). column(align => 'center', content => checkbox(name => "friendcheckbox_$number_of_checkboxes", value => $ref->{'nimi'})). endrow(); $number_of_checkboxes++; } db_end(); unlock_tables(); $friendlist = startrow(class=> 'content', bgcolor => '#FFFFFF') . column(colspan => '3',content => ' '. $trans->gettext('No friends in your friend list')). endrow() if $friendlist eq ''; $the_template =~ s/<>/$friendlist/m; $the_template =~ s/<>/$number_of_checkboxes/m; my $buttonstuff = tagged('a',{href => "javascript:REMOVE()", onMouseOver => 'doClock(); return true', content => image(src => '<>removefrommyfriends.gif', border => "0", alt => $trans->gettext('Remove selected user(s) from your friend list'))}) . '  '. tagged('a',{href => "profile_view.html?ID=$form->{'ID'}&auth=$form->{'auth'}", onMouseOver => 'doClock(); return true', content => image(src => '<>showotherusers.gif', border => "0", alt => $trans->gettext('Go to User Profiles page'))}); $the_template =~ s/<>/$buttonstuff/m; return $the_template; } ################################################################################# # 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 { my ($check, $message) = ('',''); # all checkboxes in the form are checked: are there ones selected? for(my $i=0; $i < $form->{'num_of_checkboxes'}; $i++) { if($form->{"friendcheckbox_$i"}) #if the checkbox is checked, do the stuff: { db_delete('friends',"user = '$USER' and friend = '".prepare_fordb($form->{"friendcheckbox_$i"})."'"); $check .= 'ok'; } } if(!$check) { $message = tag('div', {class => 'error'}) .$trans->gettext('No friends selected!').endtag('div');} else { $message = tag('div', {class => 'success'}) .$trans->gettext('Selected friends removed from your friend list!').endtag('div'); } return $message; }