#!/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: desktop.html,v 1.42 2002/07/21 12:06:55 inf Exp $ #"""""""""""""""""""""""""""""""""""""""""# # # # MimerDesk: Home - Desktop / login # # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # # (c) Ionstream OY 1999 - 2001 # # # # Programmed by: Teemu Arina # # Modified by: Hannes Muurinen # # # #_________________________________________# # Begin ################################## use strict; use vars qw ($APPLICATION $ACTIVEGRP $index_news_count $USER $IP $LAST_ACT $FORWARDED $TIME_USED $IDLE $form $ref $sth $DESKTOP @DESKTOP @months @days @toggles $number_of_visible_tasks $trans @DESKORDER); use lib::MimerDesk; use CGI::Carp "fatalsToBrowser"; sub print_template; sub floor; sub get_logged_users; sub get_news; sub get_links; sub get_posts; sub get_calevents; sub get_uptime; sub get_groups; sub dicsort; sub get_groupposts; sub get_systeminfo; sub get_groupinfo; sub create_box; sub toggle; sub get_tasks; sub movebox; sub get_vote; $APPLICATION = "Home - Desktop"; $index_news_count = 10; $number_of_visible_tasks = 15; # Program ################################## read_config('../config/mimerdesk.cfg'); initialize(); $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 => 'desktop',language => $config{'language'}); $APPLICATION = $trans->gettext("Home - Desktop"); @toggles = ( [1, 0, $trans->gettext('My groups'), 'mygroups.gif','groups'], [1, 1, $trans->gettext('My tasks'), 'tasks.gif','tasks'], [1, 2, $trans->gettext('Other online users'), 'currentusers.gif','online'], [1, 3, $trans->gettext('Latest vote topic'), 'tasks.gif','voting'], [1, 4, $trans->gettext('Latest links'), 'latestlinks.gif','links'], [1, 5, $trans->gettext('System information'), 'systeminfo.gif','systeminfo'], [1, 6, $trans->gettext('Upcoming calendar events'), 'cocaevents.gif','calevents'], [1, 7, $trans->gettext('Latest news headlines'), 'laneheadlines.gif','news'], [1, 8, $trans->gettext('Latest posts to the public forums'), 'latestposts.gif','posts'], # [1, 9, $trans->gettext("Latest posts to your groups' forums"), 'latestposts.gif','groupposts'], # [1, 'a', $trans->gettext("Latest news in your groups' news boards"), 'laneheadlines.gif','groupnews'], ); @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') ); @days = ( $trans->gettext('Sunday'), $trans->gettext('Monday'), $trans->gettext('Tuesday'), $trans->gettext('Wednesday'), $trans->gettext('Thursday'), $trans->gettext('Friday'), $trans->gettext('Saturday') ); ($DESKTOP) = db_select("DESKTOP,DESKORDER","users","nimi = '$USER'"); @DESKTOP = split //, $DESKTOP->{'DESKTOP'}; @DESKORDER = split //, $DESKTOP->{'DESKORDER'}; $DESKTOP = $DESKTOP->{'DESKTOP'}; if ($form->{'quit'}) {redirect("$config{'loc_server'}$config{'bin_dir'}/index.html?ID=$form->{'ID'}&auth=$form->{'auth'}&quit=quit");} elsif ($form->{'toggle'} =~ /^[0-9a]+$/) {toggle($form->{'toggle'});} elsif ($form->{'up'} =~ /^[0-9]+$/) {movebox('up',$form->{'up'});} elsif ($form->{'down'} =~ /^[0-9]+$/) {movebox('down',$form->{'down'});} print_template("$config{'theme'}_index"); ################## # Toggle boxes # ################## sub toggle { my ($toggle) = shift; my %purkka = (0 => 0, 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6, 7 => 7, 8 => 8, 9 => 9, 'a' => 10); $toggle = $purkka{$toggle}; if (@DESKTOP != @toggles) { @DESKTOP = (); foreach (@toggles) {push @DESKTOP, $_->[0];} } if (@DESKTOP[$toggle] eq '0') {@DESKTOP[$toggle] = '1';} elsif (@DESKTOP[$toggle] eq '1') {@DESKTOP[$toggle] = '0';} $DESKTOP = join "", @DESKTOP; lock_tables('WRITE', 'users'); db_update('users',{DESKTOP => $DESKTOP},"nimi = '$USER'"); unlock_tables(); } ######################### # Move boxes up / down # ######################### sub movebox { my ($oldloc,$newloc); my ($mode,$location) = @_; if (@DESKORDER != @toggles) { @DESKORDER = (); foreach (@toggles) {push @DESKORDER, $_->[1];} } if ($mode eq 'up') { $oldloc = $DESKORDER[$location]; $newloc = $DESKORDER[$location-1]; $DESKORDER[$location] = $newloc; $DESKORDER[$location-1] = $oldloc; } else { $oldloc = $DESKORDER[$location]; $newloc = $DESKORDER[$location+1]; $DESKORDER[$location] = $newloc; $DESKORDER[$location+1] = $oldloc; } lock_tables('WRITE', 'users'); db_update('users',{DESKORDER => join "", @DESKORDER},"nimi = '$USER'"); unlock_tables(); } ################################## # Create a box for the desktop # ################################## sub create_box { my ($buttons); my ($count,$title,$toggle,$content,$box,$link,$startimage,$addlink,$addlinkname) = @_; if ($count > 0) { $buttons .= tagged('a', { href => "desktop.html?ID=$form->{'ID'}&auth=$form->{'auth'}&up=$count", content => image(src => "$config{'loc_pictures2'}/minea/up.gif",height => 20,width => 20,align => 'absmiddle',alt => 'Move this box up') }); } if ($count < $#toggles) { $buttons .= tagged('a', { href => "desktop.html?ID=$form->{'ID'}&auth=$form->{'auth'}&down=$count", content => image(src => "$config{'loc_pictures2'}/minea/down.gif",height => 20,width => 20,align => 'absmiddle',alt => 'Move this box down') }); } if ($toggle) { $buttons .= tagged('a', { href => "desktop.html?ID=$form->{'ID'}&auth=$form->{'auth'}&toggle=$box", content => image(src => "$config{'loc_pictures2'}/minea/maximize.gif",height => 20,width => 20,align => 'absmiddle',alt => 'Minimize this box') }); } else { $buttons .= tagged('a', { href => "desktop.html?ID=$form->{'ID'}&auth=$form->{'auth'}&toggle=$box", content => image(src => "$config{'loc_pictures2'}/minea/minimize.gif",height => 20,width => 20,align => 'absmiddle',alt => 'Maximize this box') }); } if ($link) { $title = tagged('a',{href => "$config{'bin_dir'}/$link?auth=$form->{'auth'}&ID=$form->{'ID'}", onMouseOver => 'doClock(); return true', class => 'blackTitleLink', content => $title}); } if ($addlink && $addlinkname) { $addlink = ' - '.tagged('a',{href => "$config{'bin_dir'}/$addlink?auth=$form->{'auth'}&ID=$form->{'ID'}&action=add", onMouseOver => 'doClock(); return true', class => 'blackTitleLink', content => $addlinkname}); } $startimage = column(width => '1%',content => image(align => 'absmiddle', width => 20,height => 20,src => "$config{'loc_pictures'}/$startimage")) if $startimage; my $box = starttable(width => '95%',align => 'center',cellspacing => 1,cellpadding => 4,gridcolor => 'black'). startrow(). column(bgcolor => '#CEDFE8', content => starttable(). startrow(). $startimage. column(width => '65%',class => 'blackTitle', content => ' '.$title.$addlink). column(width => '35%',align => 'right', content => $buttons). endrow(). endtable() ). endrow(). startrow(bgcolor => 'white'); if ($toggle) { $box .= column(valign => 'top', class => 'content', content => $content); } $box .= endrow(). endtable('hasgrid').tag('br'); return $box; } ############################ # Get links of the group # ############################ sub get_links { my ($links); lock_tables('READ', 'resindex'); db_list("select link_url,link_name from resindex order by number DESC LIMIT 5"); while (my $ref = $sth->fetchrow_hashref()) { my $domain = $ref->{'link_url'}; $domain =~ s/^.+?:\/\///; $domain =~ s/^(.+?)\/.*$/$1/ if $domain =~ /\//; my @domain = split /\./, $domain; $domain = "$domain[-2].$domain[-1]"; $links .= tagged('a',{href => "$ref->{'link_url'}", class => 'contentLinkBlue', target => 'blank_', content => $ref->{'link_name'} }). ' - '. tagged('span',{ class => 'graySmall', content => $domain}). tag('br'); } db_end(); unlock_tables(); $links =~ s/(.*)
$/$1/ if $links; $links = $trans->gettext('No links.') if !$links; return $links; } ########################################################## # Get number of active sessions and the user name list # ########################################################## sub get_logged_users { my ($number_of_logged, @users, %onlinetimes); lock_tables('READ', 'sessions','users'); db_list("select sessions.USER,users.info,sessions.LAST_ACT from sessions,users where sessions.USER = users.nimi order by users.info"); while (my $ref = $sth->fetchrow_hashref()) { my $idleTime = time() - $ref->{'LAST_ACT'}; $idleTime = $idleTime / 60; $idleTime = int ($idleTime + 0.5); next if $idleTime > $config{'idle_limit'}; push @users, [$ref->{'USER'},$ref->{'info'}] if $ref->{'USER'} ne $USER && !exists($onlinetimes{$ref->{'USER'}}); $onlinetimes{$ref->{'USER'}} = $idleTime if !exists($onlinetimes{$ref->{'USER'}}) || $onlinetimes{$ref->{'USER'}} > $idleTime; } db_end(); unlock_tables(); $number_of_logged = @users; return ($number_of_logged, \@users, \%onlinetimes); } ################################################### # Get list of groups where the user is a member # ################################################### sub get_groups { my (%groups); lock_tables('READ', 'groupusers','groups'); db_list("select groups.GRPNAME,groups.GID from groupusers,groups where groupusers.USER = '$USER' and groupusers.GID = groups.GID order by GRPNAME"); while (my $ref = $sth->fetchrow_hashref()) {$groups{$ref->{'GRPNAME'}} = $ref->{'GID'};} db_end(); unlock_tables(); return \%groups; } ###################### # Get list of news # ###################### sub get_news { my ($new,$headlines,$day,$last,%months); my $lastvisit = shift; lock_tables('READ', 'md_news', 'users'); foreach $ref (db_select("md_news.headline,md_news.IDnumber,md_news.epoch,users.nimi,users.info","md_news, users","md_news.senderID = users.UID","md_news.epoch DESC","$index_news_count")) { my (undef,undef,undef,undef,$lmonth,$lyear) = utc_epoch2date($ref->{'epoch'}); $day = local_date2date_string(undef,undef,undef,undef,$lmonth,$lyear,'%sm %y'); $headlines .= tag('br') if $last && $last ne $day; $headlines .= tagged('a',{href => "md_news.html?month=$lmonth&year=$lyear&auth=$form->{'auth'}&ID=$form->{'ID'}", class => 'blackTitleLink', content => $day}). hrline().tag('br') if $last ne $day; $last = $day; if ($ref->{'submitted'} > $lastvisit) {$new = tagged('font',{color => 'red',content => '*'});} else {$new = '  ';} $headlines .= $new. tagged('a',{href => "md_news.html?month=$lmonth&year=$lyear&auth=$form->{'auth'}&ID=$form->{'ID'}&newsID=$ref->{'IDnumber'}", class => 'contentLinkBlue', content => $ref->{'headline'} } ). tagged('span',{class => 'graySmall', content => " - "}). tagged('a', {href => "profile_view.html?ID=$form->{'ID'}&auth=$form->{'auth'}&showprofile=$ref->{'nimi'}", onMouseOver => 'doClock(); return true', class=> 'graySmall', content => $ref->{'info'}}). tag('br'); } unlock_tables(); $headlines = $trans->gettext('No news.') if !$headlines; return $headlines; } ############################ # Get list of group news # ############################ sub get_groupnews { my ($new,$headlines,$day,$last,%months,$groups,$groupname,$group_name_added); my $lastvisit = shift; $groups = get_groups(); foreach $groupname (sort dicsort keys %$groups) { ($day,$last,$group_name_added) = ('','',''); lock_tables('READ', "$groups->{$groupname}_md_news", 'users'); foreach $ref (db_select("$groups->{$groupname}_md_news.headline,$groups->{$groupname}_md_news.IDnumber,$groups->{$groupname}_md_news.epoch,users.nimi,users.info","$groups->{$groupname}_md_news, users","$groups->{$groupname}_md_news.senderID = users.UID","$groups->{$groupname}_md_news.epoch DESC","$index_news_count")) { if(!$group_name_added) { $headlines .= tagged('a',{href => "md_news.html?auth=$form->{'auth'}&ID=$form->{'ID'}&grouptool=$groups->{$groupname}&changeGroup=$groups->{$groupname}&skipredir=yes", class => 'blackTitleLink', content => $groupname}).hrline().tag('br'); $group_name_added = 1; } my (undef,undef,undef,undef,$lmonth,$lyear) = utc_epoch2date($ref->{'epoch'}); $day = local_date2date_string(undef,undef,undef,undef,$lmonth,$lyear,'%sm %y'); $headlines .= tag('br') if $last && $last ne $day; $headlines .= tagged('a',{href => "md_news.html?month=$lmonth&year=$lyear&auth=$form->{'auth'}&ID=$form->{'ID'}&grouptool=$groups->{$groupname}&changeGroup=$groups->{$groupname}&skipredir=yes", class => 'blackTitleLink', content => "  $day"}). tag('br') if $last ne $day; $last = $day; if ($ref->{'submitted'} > $lastvisit) {$new = tagged('font',{color => 'red',content => '*'});} else {$new = '    ';} $headlines .= $new. tagged('a',{href => "md_news.html?month=$lmonth&year=$lyear&auth=$form->{'auth'}&ID=$form->{'ID'}&newsID=$ref->{'IDnumber'}&grouptool=$groups->{$groupname}&changeGroup=$groups->{$groupname}&skipredir=yes", class => 'contentLinkBlue', content => $ref->{'headline'} } ). tagged('span',{class => 'graySmall', content => " - "}). tagged('a', {href => "profile_view.html?ID=$form->{'ID'}&auth=$form->{'auth'}&showprofile=$ref->{'nimi'}", onMouseOver => 'doClock(); return true', class=> 'graySmall', content => $ref->{'info'}}). tag('br'); } unlock_tables(); } $headlines = $trans->gettext('No group news.') if !$headlines; return $headlines; } ##################################### # Get list of posts to the forums # ##################################### sub get_posts { my ($new,$posts,%forums,$postings,@forums,%forumids); my $lastvisit = shift; lock_tables('READ', 'mboards','boardconfig','users','unreadMSG'); foreach $ref (db_select("mboards.forum as forum,users.info,users.nimi,mboards.postdate,mboards.id,mboards.thread_id,mboards.topic,boardconfig.forum as forum2","mboards,boardconfig,users,unreadMSG","mboards.forum = boardconfig.id and mboards.sender = users.nimi and unreadMSG.user='$USER' and unreadMSG.msgID=mboards.id and unreadMSG.msgTable='mboards'","mboards.postdate DESC","$index_news_count")) { $ref->{'id'} = $ref->{'thread_id'} if $ref->{'thread_id'}; if (length($ref->{'topic'}) > 50) { $ref->{'topic'} = substr $ref->{'topic'}, 0, 48; $ref->{'topic'} .= "..."; } if ($ref->{'postdate'} > $lastvisit) {$new = tagged('font',{color => 'red',content => '*'});} else {$new = '  ';} $posts = $new. tagged('a',{href => "boards.html?board=$ref->{'forum'}&mid=$ref->{'id'}&auth=$form->{'auth'}&ID=$form->{'ID'}&record=yes", class => 'contentLink', content => tagged('font',{class => 'contentLinkBlue', content => $ref->{'topic'} } ) } ). tagged('span',{class => 'graySmall', content => ' - '}). tagged('a', {href => "profile_view.html?ID=$form->{'ID'}&auth=$form->{'auth'}&showprofile=$ref->{'nimi'}", onMouseOver => 'doClock(); return true', class=> 'graySmall', content => $ref->{'info'}}). tag('br'); push @{$forums{$ref->{'forum2'}}}, $posts; $forumids{$ref->{'forum2'}} = $ref->{'forum'}; } unlock_tables(); foreach (sort keys %forums) { $postings = tagged('a',{href => "boards.html?board=$forumids{$_}&auth=$form->{'auth'}&ID=$form->{'ID'}", class => 'blackTitleLink', content => $_}). hrline().tag('br'); foreach (@{$forums{$_}}) {$postings .= $_;} push @forums, $postings; } $postings = join tag('br'), @forums; $postings = $trans->gettext('No posts.') if !$postings; return $postings; } ########################################### # Get list of posts to the group forums # ########################################### sub get_groupposts { my ($new,$posts,%forums,$postings,@forums,%forumids,$allposts,$groupname); my $lastvisit = shift; my $groups = shift; $groups = get_groups();# if !$toggles{'groups'}->[0]; # the groups aren't previously fetched if $toggles{'groups'}->[0] equals 0 foreach $groupname (sort dicsort keys %$groups) { %forums = (); @forums = (); lock_tables('READ', "$groups->{$groupname}_mboards","$groups->{$groupname}_boardconfig","users",'unreadMSG'); foreach $ref (db_select("$groups->{$groupname}_mboards.forum as forum,users.info,users.nimi,$groups->{$groupname}_mboards.postdate,$groups->{$groupname}_mboards.id,$groups->{$groupname}_mboards.thread_id,$groups->{$groupname}_mboards.topic,$groups->{$groupname}_boardconfig.forum as forum2", "$groups->{$groupname}_mboards,$groups->{$groupname}_boardconfig,users,unreadMSG", "$groups->{$groupname}_mboards.forum = $groups->{$groupname}_boardconfig.id and $groups->{$groupname}_mboards.sender = users.nimi and unreadMSG.user='$USER' and unreadMSG.msgID=$groups->{$groupname}_mboards.id and unreadMSG.msgTable='$groups->{$groupname}_mboards'", "$groups->{$groupname}_mboards.postdate DESC","$index_news_count")) { $ref->{'id'} = $ref->{'thread_id'} if $ref->{'thread_id'}; if (length($ref->{'topic'}) > 50) { $ref->{'topic'} = substr $ref->{'topic'}, 0, 48; $ref->{'topic'} .= "..."; } if ($ref->{'postdate'} > $lastvisit) {$new = tagged('font',{color => 'red',content => '*'});} else {$new = '    ';} $posts = $new. tagged('a',{href => "boards.html?board=$ref->{'forum'}&mid=$ref->{'id'}&auth=$form->{'auth'}&ID=$form->{'ID'}&grouptool=$groups->{$groupname}&changeGroup=$groups->{$groupname}&skipredir=yes&record=yes", class => 'contentLinkBlue', content => tagged('font',{class => 'contentLink', content => $ref->{'topic'} } ) } ). tagged('span',{class => 'graySmall', content => " - "}). tagged('a', {href => "profile_view.html?ID=$form->{'ID'}&auth=$form->{'auth'}&showprofile=$ref->{'nimi'}", onMouseOver => 'doClock(); return true', class=> 'graySmall', content => $ref->{'info'}}). tag('br'); push @{$forums{$ref->{'forum2'}}}, $posts; $forumids{$ref->{'forum2'}} = $ref->{'forum'}; } unlock_tables(); foreach (sort dicsort keys %forums) { $postings = tagged('a',{href => "boards.html?board=$forumids{$_}&auth=$form->{'auth'}&ID=$form->{'ID'}&grouptool=$groups->{$groupname}&changeGroup=$groups->{$groupname}&skipredir=yes", class => 'blackTitleLink', content => "  $_"}).tag('br'); foreach (@{$forums{$_}}) {$postings .= $_;} push @forums, $postings; } $postings = join tag('br'), @forums; $allposts .= tag('br') if $postings && $allposts; $allposts .= tagged('span',{class => 'blackTitleSec', content => tagged('a',{href => "boards.html?auth=$form->{'auth'}&ID=$form->{'ID'}&grouptool=$groups->{$groupname}&changeGroup=$groups->{$groupname}&skipredir=yes", class => 'blackTitleLink', content => $groupname })}). hrline().tag('br') if $postings; $allposts .= $postings if $postings; } $allposts = $trans->gettext('No posts.') if !$allposts; return $allposts; } ########################################## # Get list of upcoming calendar events # ########################################## sub get_calevents { my ($i,$new,$calevents,$day,$last,$endday); my $current_epoch = time(); lock_tables('READ', 'calendar'); foreach $ref (db_select("epoch,time,end_epoch,summary,IDnumber","calendar","user = '$USER' and epoch >= '$current_epoch'","epoch")) { $i++; last if $i > $index_news_count; my (undef,$lmin,$lhour,$lday,$lmonth,$lyear,$day_of_week) = utc_epoch2date($ref->{'epoch'}); my (undef,$emin,$ehour,$eday,$emonth,$eyear,$eday_of_week) = utc_epoch2date($ref->{'end_epoch'}); $day = "$months[$lmonth] $lyear"; if ($last ne $day) { $calevents .= endtable() if $calevents; $calevents .= tag('br') if $last; $calevents .= tagged('a',{href => "calendar.html?auth=$form->{'auth'}&ID=$form->{'ID'}&view=month&year=$lyear&month=$lmonth", class => 'blackTitleLink', content => $day}). hrline().tag('br'); $calevents .= starttable(width => '100%'); } $last = $day; if ($lday eq $eday && $lmonth eq $emonth) {$endday = "$ehour:$emin";} else { $endday = tagged('a',{href => "calendar.html?auth=$form->{'auth'}&ID=$form->{'ID'}&view=day&year=$eyear&month=$emonth&day=$eday", class => 'graySmall', content => $eday } ) . '.' . tagged('a',{href => "calendar.html?auth=$form->{'auth'}&ID=$form->{'ID'}&view=month&year=$eyear&month=$emonth", class => 'graySmall', content => $emonth } ) . " $ehour:$emin"; } my ($clock_and_end); $clock_and_end = "$lhour:$lmin~$endday" if $ref->{'time'} ne 'full'; $calevents .= startrow(). column(valign => 'top', width => 1, class => 'graySmall', content => "  " . tagged('a',{href => "calendar.html?auth=$form->{'auth'}&ID=$form->{'ID'}&view=day&year=$lyear&month=$lmonth&day=$lday", class => 'graySmall', content => $days[$day_of_week] } ) . " " ). column(valign => 'top', width => 120, class => 'graySmall', content => tagged('a',{href => "calendar.html?auth=$form->{'auth'}&ID=$form->{'ID'}&view=day&year=$lyear&month=$lmonth&day=$lday", class => 'graySmall', content => $lday } ) . " $clock_and_end   " ). column(valign => 'top', width => '90%', class => 'content', content => tagged('a',{href => "calendar.html?selectedGO=View&auth=$form->{'auth'}&ID=$form->{'ID'}&numofcheckboxes=1&checkb0=$ref->{'IDnumber'}", class => 'contentLinkBlue', content => $ref->{'summary'} } ) ). endrow(); } unlock_tables(); $calevents .= endtable() if $calevents; $calevents = $trans->gettext('No upcoming calendar events.') if !$calevents; return $calevents; } ####################### # Get server uptime # ####################### sub get_uptime { my ($uptime); open UPTIME, "); close UPTIME; $uptime =~ s/^(\d+)\.\d\d \d+\.\d\d$/$1/; my $days = int($uptime / 60 / 60 / 24); $uptime = $uptime - ($days * 60 * 60 * 24); my $hours = int($uptime / 60 / 60); $uptime = $uptime - ($hours * 60 * 60); my $minutes = int($uptime / 60); foreach ($hours,$minutes) {if ($_ < 10) {$_ = "0".$_;}} return "${days} days, ${hours}:${minutes}"; } #################### # Get systeminfo # #################### sub get_systeminfo { my ($allvisit,$lastvisit) = @_; my ($logged) = get_logged_users($lastvisit); $logged++; my $systeminfo = $trans->gettext('Number of users online: '). tagged('a',{href => "online.html?auth=$form->{'auth'}&ID=$form->{'ID'}", class => 'blackTitleLink', content => $logged } ).tag('br'); $systeminfo .= $trans->gettext('Number of users in chatrooms: '). tagged('a',{href => "chat.html?auth=$form->{'auth'}&ID=$form->{'ID'}", class => 'blackTitleLink', content => row_count('chat_users') } ).tag('br'); $systeminfo .= $trans->gettext('Logins so far: '). tagged('b',{content => $allvisit}).tag('br'); $systeminfo .= $trans->gettext('Number of registered users: '). tagged('b',{content => row_count('users')}).tag('br'); $systeminfo .= $trans->gettext('Number of registered groups: '). tagged('b',{content => row_count('groups')}).tag('br'); $systeminfo .= $trans->gettext('Server uptime: '). tagged('b',{content => get_uptime()}); return $systeminfo; } ################## # Get votes # ################## sub get_vote { my(@votes, @uservid, $vid, $cnt, $votedesk, %voteinfo, @vars, $ref,$count); lock_tables('READ', 'votes', 'vote_users'); db_list("select VID, EXPIRATION, STATUS from votes order by vid desc"); while ($ref = $sth->fetchrow_hashref()) { if ($ref->{'EXPIRATION'} < time() || $ref->{'STATUS'} == 0) { next; } else { push @votes, $ref->{'VID'}; } } db_end(); db_list("select VID from vote_users where user = '$USER' order by vid desc"); while ($ref = $sth->fetchrow_hashref()) { push @uservid, $ref->{'VID'}; } db_end(); foreach my $voteid (@votes) { if (!grep {$_ eq $voteid} @uservid) { $vid = $voteid; last; } } unlock_tables(); return $trans->gettext('No new votes.') if !$vid; lock_tables('READ', 'vote_vars', 'votes'); db_list("select votes.TOPIC,vote_vars.VID,vote_vars.VAR from vote_vars,votes where votes.VID = '$vid' and vote_vars.VID = votes.VID order by vote_vars.VARID"); while ($ref = $sth->fetchrow_hashref()) { $voteinfo{'topic'} = $ref->{'TOPIC'}; $voteinfo{'vid'} = $ref->{'VID'}; push @vars, $ref->{'VAR'}; } db_end(); unlock_tables(); $votedesk .= tagged('a',{href => "vote.html?auth=$form->{'auth'}&ID=$form->{'ID'}&vid=$voteinfo{'vid'}", class => 'blackTitleLink', content => $voteinfo{'topic'}}).hrline().tag('br'); $cnt = 0; foreach (@vars) { $count++; $votedesk .= "$count. ". tagged('a', {href => "vote.html?ID=$form->{'ID'}&auth=$form->{'auth'}&vid=$voteinfo{'vid'}&vote=$cnt", content => $_.' '}). tag('br'); $cnt++; } unlock_tables(); return ($votedesk); } ################## # Get my tasks # ################## sub get_tasks { my ($duedate,@duedate,@undefinedtaskrowlist,@definedtaskrowlist,$tasks); lock_tables('READ', 'todo'); db_list("SELECT * FROM todo WHERE USER = '$USER' AND STATUS = 1 order by DUE_DATE,PRIORITY"); while (my $ref = $sth->fetchrow_hashref()) { if (!$ref->{'DUE_DATE'}) {$duedate = '-';} else { my (undef,undef,undef,$day_of_month,$month,$year) = utc_epoch2date($ref->{'DUE_DATE'}); if ($ref->{'DUE_DATE'} < time()) { $duedate = tagged('span',{class => 'error', content => "$year/$month/$day_of_month"}); } else {$duedate = "$day_of_month.$month.$year";} } ($ref->{'SUMMARY'}) = html_escape($ref->{'SUMMARY'}); my $taskrow = startrow(). column(class => 'content', valign=>'top', content =>tagged('center',{content => $ref->{'PRIORITY'}})). column(class => 'content', valign=>'top', content => tagged('a',{href => "todo_add.html?auth=$form->{'auth'}&ID=$form->{'ID'}&action=edit&todo=$ref->{'ID'}", class => 'contentLinkBlue', content => $ref->{'SUMMARY'}} )). column(class => 'content', valign=>'top', content =>tagged('center',{content => $duedate})). endrow(); if ($ref->{'DUE_DATE'}) { push @definedtaskrowlist, $taskrow;} else { push @undefinedtaskrowlist, $taskrow;} } push @definedtaskrowlist, @undefinedtaskrowlist; splice @definedtaskrowlist, $number_of_visible_tasks; $tasks .= join "", @definedtaskrowlist; unlock_tables(); $tasks = starttable(cellpadding => 2). startrow(). column(class => 'blackTitle',content => tagged('center',{content => $trans->gettext('Pr')})). column(class => 'blackTitle',content => $trans->gettext('Summary')). column(class => 'blackTitle',content => tagged('center',{content => $trans->gettext('Due date')})). endrow().$tasks.endtable() if $tasks; $tasks = $trans->gettext('No tasks.') if !$tasks; return $tasks; } ############################## # Get my group information # ############################## sub get_groupinfo { my $lastvisit = shift; my ($groups,$redposts,$countposts); my $groupref = get_groups(); if ($groupref) { foreach (sort dicsort keys %$groupref) { $countposts = undef; $redposts = undef; lock_tables('READ', "$groupref->{$_}_mboards","$groupref->{$_}_md_news",'sessions','groupusers','unreadMSG'); foreach $ref (db_select("$groupref->{$_}_mboards.postdate", "$groupref->{$_}_mboards,unreadMSG", "unreadMSG.user='$USER' and unreadMSG.msgID=$groupref->{$_}_mboards.id and unreadMSG.msgTable='$groupref->{$_}_mboards'", "$groupref->{$_}_mboards.postdate DESC","$index_news_count")) { $redposts = 1 if $ref->{'postdate'} > $lastvisit; $countposts++; } if ($redposts) { $countposts = tagged('font',{color => 'red',content => $countposts}); } db_list("select distinct groupusers.USER from groupusers,sessions where groupusers.USER = sessions.USER and GID = '$groupref->{$_}'"); my $countusers = $sth->rows(); db_end(); db_list("select count(epoch) from $groupref->{$_}_md_news where epoch > $lastvisit"); my $countnews = $sth->fetchrow_arrayref(); db_end(); unlock_tables(); $countusers-- if $countusers; $groups .= startrow(). column(class => 'content', content => tagged('a',{href => "group.html?auth=$form->{'auth'}&ID=$form->{'ID'}&changeGroup=$groupref->{$_}", class => 'contentLinkBlue', content => $_ } ) ). column(class => 'content', content =>tagged('center',{content => $countnews->[0] || '0'})). column(class => 'content', content =>tagged('center',{content => $countposts || '0'})). column(class => 'content', content =>tagged('center',{content => $countusers || '0'})). endrow(); } } $groups = starttable(cellpadding => 2). startrow(). column(content => ' '). column(width => '1',content => tagged('center',{content => image(src => "$config{'loc_pictures'}/groupnews.gif", height => 19, width => 20, alt => $trans->gettext('New group news')) })). column(width => '1',content => tagged('center',{content => image(src => "$config{'loc_pictures'}/groupposts.gif", height => 19, width => 20, alt => $trans->gettext('New group posts')) })). column(width => '1',content => tagged('center',{content => image(src => "$config{'loc_pictures'}/onlineusers.gif", height => 19, width => 20, alt => $trans->gettext('Users online')) })). endrow().$groups.endtable() if $groups; $groups = $trans->gettext('No groups.') if !$groups; return ($groups,$groupref); } #"""""""""""""""""""""""""""""""""""""""# # dicsort - Use dictionary sort # #---------------------------------------# # sort dicsort @array # #_______________________________________# sub dicsort { # Someone should write this function again so # that it will use some kind of sorting algorithm! my $da = lc $a; my $db = lc $b; $da =~ s/[\W_]+//g; $db =~ s/[\W_]+//g; $da cmp $db; } ################################## # Read template and process it # ################################## sub print_template { my ($ref,$fulltemplate,$lastvisit,$realname,$groups,$groupref,$systeminfo,$online,$groupcount,$tasks, $allvisit,$current_date, $chatusers, $new, @LEFT, @RIGHT); my ($template,$message) = @_; print_header('pragma'); lock_tables('READ', 'users','sys_info'); db_list("SELECT info,lastpage FROM users where nimi = '$USER'"); while (my $ref = $sth->fetchrow_hashref()) { $realname = $ref->{'info'}; $lastvisit = $ref->{'lastpage'}; } db_end(); ($lastvisit) = split /\|/, $lastvisit; db_list("SELECT con_value FROM sys_info"); while (my $ref = $sth->fetchrow_hashref()) {$allvisit = $ref->{'con_value'};} db_end(); unlock_tables(); foreach my $toggle (@toggles) { next if !$toggle->[0]; my $count = 0; foreach my $counted (@DESKORDER) { last if $toggle->[1] eq $counted; $count++; } if ($toggle->[4] eq 'links') { my $links = get_links() if $DESKTOP[4]; $LEFT[$count] = create_box($count,$toggle->[2],$DESKTOP[4],$links, $toggle->[1],'resources.html',$toggle->[3]); } elsif ($toggle->[4] eq 'systeminfo') { $systeminfo = get_systeminfo($allvisit,$lastvisit) if $DESKTOP[5]; $LEFT[$count] = create_box($count,$toggle->[2],$DESKTOP[5],$systeminfo, $toggle->[1],'',$toggle->[3]); } elsif ($toggle->[4] eq 'groups') { ($groups,$groupref) = get_groupinfo($lastvisit) if $DESKTOP[0]; $LEFT[$count] = create_box($count,$toggle->[2],$DESKTOP[0],$groups, $toggle->[1], 'groups.html',$toggle->[3]); } elsif ($toggle->[4] eq 'tasks') { $tasks = get_tasks() if $DESKTOP[1]; $LEFT[$count] = create_box($count,$toggle->[2],$DESKTOP[1],$tasks, $toggle->[1], 'todo.html', $toggle->[3], 'todo_add.html', $trans->gettext('Add task')); } elsif ($toggle->[4] eq 'voting') { $tasks = get_vote() if $DESKTOP[3]; $LEFT[$count] = create_box($count,$toggle->[2],$DESKTOP[3],$tasks, $toggle->[1], 'vote.html', $toggle->[3]); } elsif ($toggle->[4] eq 'online') { if ($DESKTOP[2]) { my ($logged, $users, $onlinetimes) = get_logged_users($lastvisit); if ($users) { $online = starttable(); foreach my $user (@$users) { $online .= startrow(). column(class => 'content',width => '1%',content => tagged('a', {href => "profile_view.html?ID=$form->{'ID'}&auth=$form->{'auth'}&showprofile=$user->[0]", onMouseOver => 'doClock(); return true', class=> 'blackTitleSec', content => $user->[0]})). column(class => 'content',width => '98%',content => ' '.' '.' '.tagged('a', {class => 'contentLinkBlue', href => "profile_view.html?ID=$form->{'ID'}&auth=$form->{'auth'}&showprofile=$user->[0]", onMouseOver => 'doClock(); return true', content => $user->[1]})). column(class => 'content', align => 'right', width => '1%', content => ' '.tagged('font',{color => 'gray', content => "$onlinetimes->{$user->[0]} ". $trans->gettext('min'). " ". $trans->gettext('idle') })). endrow(); } $online .= endtable(); $online .= tagged('span',{class => 'graySmall', content => sprintf($trans->gettext('Total: %s'),$logged)}) if $logged; } $online = $trans->gettext('No other users online.') if !$logged; } $LEFT[$count] = create_box($count,$toggle->[2],$DESKTOP[2],$online, $toggle->[1], 'online.html',$toggle->[3]); } elsif ($toggle->[4] eq 'calevents') { my $calevents = get_calevents() if $DESKTOP[6]; $LEFT[$count] = create_box($count,$toggle->[2],$DESKTOP[6],$calevents,$toggle->[1], 'calendar.html', $toggle->[3], 'calendar_add_event.html', $trans->gettext('Add event')); } elsif ($toggle->[4] eq 'news') { my $latestnews = get_news($lastvisit) if $DESKTOP[7]; $LEFT[$count] = create_box($count,$toggle->[2],$DESKTOP[7],$latestnews,$toggle->[1], 'md_news.html',$toggle->[3]); } elsif ($toggle->[4] eq 'groupnews') { my $latestnews = get_groupnews($lastvisit) if $DESKTOP[10]; $LEFT[$count] = create_box($count,$toggle->[2],$DESKTOP[10],$latestnews,$toggle->[1], '',$toggle->[3]); } elsif ($toggle->[4] eq 'posts') { my $latestposts = get_posts($lastvisit) if $DESKTOP[8]; $LEFT[$count] = create_box($count,$toggle->[2],$DESKTOP[8],$latestposts,$toggle->[1], 'boards.html',$toggle->[3]); } elsif ($toggle->[4] eq 'groupposts') { my $groupposts = get_groupposts($lastvisit,$groupref) if $DESKTOP[9]; $LEFT[$count] = create_box($count,$toggle->[2],$DESKTOP[9],$groupposts,$toggle->[1],'',$toggle->[3]); } } my ($sec,$min,$hour,$mday,$mon,$year,$day_of_week) = utc_epoch2date(time()); $current_date = "$days[$day_of_week] $mday @months[$mon] $year"; $ref = get_template('maintemplate',$template); $ref->{'maintemplate'} =~ s/<>/$ref->{$template}/m; $fulltemplate = $ref->{'maintemplate'}; $fulltemplate = add_popups($fulltemplate, $USER, $form->{'auth'}, $form->{'ID'}); $fulltemplate =~ s/<>/$realname/m; $fulltemplate =~ s/<>/$current_date/m; @RIGHT = splice(@LEFT, 0, @LEFT / 2); my $LEFT = join "", @LEFT; my $RIGHT = join "", @RIGHT; $fulltemplate =~ s/<>/$RIGHT/m; $fulltemplate =~ s/<>/$LEFT/m; $ref = get_template('js_doClock', 'js_help', 'js_gotosite'); my $stuff = join "", ($ref->{'js_doClock'},$ref->{'js_help'},$ref->{'js_gotosite'}); $fulltemplate =~ s/<>/$stuff/m; $APPLICATION = 'Home - Desktop'; $fulltemplate =~ s/<>/MimerDesk\: $APPLICATION/m; $fulltemplate = create_buttons($fulltemplate, 'Home', 'Desktop', $form); $fulltemplate =~ s/<>/minea/gm; $fulltemplate = replace_tags($fulltemplate, $USER, $form->{'auth'}, $form->{'ID'}, $TIME_USED); $fulltemplate =~ s/<>/index.html/m; print $fulltemplate; db_end('disconnect'); exit; }