#!/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: addressbook.html #"""""""""""""""""""""""""""""""""""""""""# # # # MimerDesk: Addressbook # # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # # (c) Ionstream OY 1999 - 2001 # # # # Programmed by: Teemu Vainio # # # #_________________________________________# use strict; use vars qw ($APPLICATION $ACTIVEGRP $ARTICLE $MONTH $USER $IP $LAST_ACT $trans $ADDRESSBOOKUSER $FORWARDED $TIME_USED $IDLE $GROUPACTIVOR $ADDRESSBOOK $form $ref $sth $addressbooklist $viewmodebutton $htmlcolors $admin_status $grouptoolize $buttons); use lib::MimerDesk; use CGI::Carp "fatalsToBrowser"; $APPLICATION = 'Personal - Contacts'; sub print_addressbook; sub print_template; sub viewmodebutton; ###################### # # Main program # # 1. Does the basic i-system stuff # 2. If order isn't given, use the default values.. # 3. Gets addressbook from database # 4. Prints template read_config('../config/mimerdesk.cfg'); $htmlcolors = initialize('colors'); $form = decode_multipart(); $form->{'ID'} =~ tr/0-9//cd; $form->{'auth'} =~ tr/0-9a-z//cd; ($USER, $IP, $LAST_ACT, $FORWARDED, $TIME_USED, $IDLE, $ACTIVEGRP) = authenticate($form->{'ID'}, $form->{'auth'}, $form->{'changeGroup'}); $trans = lib::MimerDesk->new_gettext(program => 'contacts',language => $config{'language'}); $addressbooklist = undef; $ADDRESSBOOK = 'addressbook'; $ADDRESSBOOKUSER = "USER = '$USER'"; $grouptoolize = undef; $buttons = 'Personal'; ### groups if ($form->{'grouptool'} =~ /^\d+$/) { $APPLICATION =~ s/Personal/Group/; $buttons = 'Group'; $grouptoolize = "&grouptool=$form->{'grouptool'}"; lock_tables('READ', 'groupusers'); db_list("SELECT RIGHTS,USER FROM groupusers where USER = '$USER' and GID = '$form->{'grouptool'}'"); while (my $ref = $sth->fetchrow_hashref()) { $admin_status = $ref->{'RIGHTS'}; $GROUPACTIVOR = $ref->{'USER'}; } db_end(); unlock_tables(); if (!$GROUPACTIVOR) { $admin_status = 'A0'; } else { $ADDRESSBOOK = "$form->{'grouptool'}_$ADDRESSBOOK"; $ADDRESSBOOKUSER = "GID = $form->{'grouptool'}"; } } else {$admin_status = 'A0';} $APPLICATION = $trans->gettext($APPLICATION); if ($form->{'order'} eq ''){$form->{'order'} = 'LASTNAME';} print_addressbook(); print_template("$config{'theme'}_addressbook"); ########################## # ____ # # ___ | | | \ ___ # # / \ | | | / / \ # # \___ | | |--< \___ # # \ | | | \ \ # # \___/ \__/ |___/ \___/ # # # ########################## ############## # print_addressbook # # Gets user's addressbook from db and forms it for viewing # # 1. Gets information from db # 2. Fixes due date into european style (yyyy-mm-dd) --> (dd.mm.yyyy) # or changes it to 'none' if it doesn't exist # 3. Selects correct statuspicture # 4. Forms complete addressbook and saves it into $addressbooklist # sub print_addressbook { my ($name, $address, $mobile, $viewcategory, $category, $id, @row); if ($form->{'viewcategory'} eq 'every' || $form->{'viewcategory'} eq '') {$viewcategory = '';} elsif ($form->{'viewcategory'} eq 'undefined') {$viewcategory = "AND CATEGORY = ''";} else { $viewcategory = "AND CATEGORY = '".prepare_fordb($form->{'viewcategory'})."'"; } $addressbooklist = starttable(width => '95%',align => 'center',cellspacing => 1,cellpadding => 4,gridcolor => 'black'). startrow(bgcolor => "$htmlcolors->{'title'}"); foreach ([$trans->gettext('Name'),'NAME'],[$trans->gettext('Address'),'ADDRESS'], [$trans->gettext('Mobilephone'),'MOBILE'],[$trans->gettext('Category'),'CATEGORY']) { $addressbooklist .= column(class => 'blackTitleLink', content => tagged('a',{class => 'blackTitleLink', href => "addressbook.html?auth=$form->{'auth'}$grouptoolize&ID=$form->{'ID'}&order=".encodeurl($_->[1])."&viewcategory=".encodeurl($form->{'viewcategory'}), content => html_escape($_->[0]).' '})); } $addressbooklist .= endrow(); lock_tables('READ',$ADDRESSBOOK); db_list("SELECT * FROM $ADDRESSBOOK WHERE $ADDRESSBOOKUSER $viewcategory order by '".prepare_fordb($form->{'order'})."'"); while (my $ref = $sth->fetchrow_hashref()) { $name = $ref->{'NAME'}; $address = $ref->{'ADDRESS'}; $mobile = $ref->{'MOBILE'}; $category = $ref->{'CATEGORY'}; $id = $ref->{'ID'}; if ($category eq '') {$category = $trans->gettext('Undefined');} $name = tagged('a',{href => "addressbook_add.html?auth=$form->{'auth'}$grouptoolize&ID=$form->{'ID'}&action=edit&number=$id&order=".encodeurl($form->{'order'})."&viewcategory=".encodeurl($form->{'viewcategory'}), content => html_escape($name)}); $addressbooklist .= startrow(); $addressbooklist .= column(bgcolor => 'white',class => 'content',content => $name.' '); $addressbooklist .= column(bgcolor => 'white',class => 'content',content => html_escape($address).' '); $addressbooklist .= column(bgcolor => 'white',class => 'content',content => html_escape($mobile).' '); $addressbooklist .= column(bgcolor => 'white',class => 'content',content => html_escape($category).' '); $addressbooklist .= endrow(); } $addressbooklist .= startrow(). column(bgcolor => 'white', colspan => '4', class => 'blackTitle', content => $trans->gettext('No contacts.') ). endrow() if !$id; db_end(); db_list("select count(*) from $ADDRESSBOOK where $ADDRESSBOOKUSER"); my $counter = $sth->fetchrow_arrayref(); db_end(); unlock_tables(); $addressbooklist .= endtable('hasgrid'); $addressbooklist .= starttable(width => '95%',align => 'center',cellspacing => 3,cellpadding => 2). startrow(). column(class => 'content',align => 'right', content => $trans->gettext('Total number of entries: ').tagged('b',{content => $counter->[0]})). endrow(). endtable(); $viewmodebutton = viewmodebutton(); } ############################# # print_template # # Prints template # sub print_template { my ($template, $ref, $fulltemplate, $add_button); $template = shift; print_header('pragma'); $ref = get_template('maintemplate',$template); $ref->{'maintemplate'} =~ s/<>/$ref->{$template}/m; $fulltemplate = $ref->{'maintemplate'}; $fulltemplate = create_buttons($fulltemplate, $buttons, 'Contacts', $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; $add_button = tagged('a', {href => "addressbook_add.html?auth=$form->{'auth'}$grouptoolize&ID=$form->{'ID'}&action=add&order=".encodeurl($form->{'order'})."&viewcategory=".encodeurl($form->{'viewcategory'}), content => image(src => "$config{'loc_pictures'}/add.gif") } ) if $admin_status =~ /A0/; $fulltemplate =~ s/<>/$add_button/ms; $fulltemplate =~ s/<>/$addressbooklist/ms; $fulltemplate =~ s/<>/html_escape($form->{'order'})/gme; $fulltemplate =~ s/<>/$viewmodebutton/sm; $fulltemplate =~ s/<>/html_escape($form->{'viewcategory'})/gme; $fulltemplate =~ s/<>/$grouptoolize/gme; $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; } ################### # viewmodebutton # # Forms the god dääm funky viewmodebutton # sub viewmodebutton { my @categories; lock_tables('READ', $ADDRESSBOOK); db_list("SELECT DISTINCT category FROM $ADDRESSBOOK WHERE $ADDRESSBOOKUSER order by category"); while (my $ref = $sth->fetchrow_hashref()) { next if ($ref->{'category'} eq ''); push @categories, $ref->{'category'}; } db_end(); unlock_tables(); my $categorybutton = tag('select', {name => 'viewcategory', onChange => 'return change_view();'}); if ('every' eq $form->{'viewcategory'}) { $categorybutton .= tagged('option',{value => "addressbook.html?auth=$form->{'auth'}$grouptoolize&ID=$form->{'ID'}&order=".encodeurl($form->{'order'})."&viewcategory=every", content => $trans->gettext('Every')}, 'selected'); } else { $categorybutton .= tagged('option',{value => "addressbook.html?auth=$form->{'auth'}$grouptoolize&ID=$form->{'ID'}&order=".encodeurl($form->{'order'})."&viewcategory=every", content => $trans->gettext('Every')}); } if ('undefined' eq $form->{'viewcategory'}) { $categorybutton .= tagged('option',{value => "addressbook.html?auth=$form->{'auth'}$grouptoolize&ID=$form->{'ID'}&order=".encodeurl($form->{'order'})."&viewcategory=undefined", content => $trans->gettext('Undefined')}, 'selected'); } else { $categorybutton .= tagged('option',{value => "addressbook.html?auth=$form->{'auth'}$grouptoolize&ID=$form->{'ID'}&order=".encodeurl($form->{'order'})."&viewcategory=undefined", content => $trans->gettext('Undefined')}); } foreach (@categories) { if ($_ eq $form->{'viewcategory'}) { $categorybutton .= tagged('option',{value => "addressbook.html?auth=$form->{'auth'}$grouptoolize&ID=$form->{'ID'} &order=".encodeurl($form->{'order'})."&viewcategory=".encodeurl($_), content => html_escape($_)}, 'selected'); } else { $categorybutton .= tagged('option',{value => "addressbook.html?auth=$form->{'auth'}$grouptoolize&ID=$form->{'ID'} &order=".encodeurl($form->{'order'})."&viewcategory=".encodeurl($_), content => html_escape($_)}); } } $categorybutton .= tag('/select'); return tagged('span', {class => 'content', content => sprintf($trans->gettext("View %s category"),$categorybutton) }); }