#!/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: todo.html #"""""""""""""""""""""""""""""""""""""""""# # # # MimerDesk: ToDo list # # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # # (c) Ionstream OY 1999 - 2001 # # # # Programmed by: Teemu Vainio # # Modified by: Hannes Muurinen # #_________________________________________# use strict; use vars qw ($APPLICATION $ACTIVEGRP $ARTICLE $MONTH $USER $IP $LAST_ACT $FORWARDED $TIME_USED $IDLE $form $ref $sth $todolist $viewmodebutton $htmlcolors $trans %default_secondary_sort %priority_class %priority_text); use lib::MimerDesk; use CGI::Carp "fatalsToBrowser"; sub print_todo; sub print_template; sub change_status; sub purge; sub viewmodebutton; $APPLICATION='Personal - Tasks'; ###################### # # Main program # # 1. Does the basic i-system stuff # 2. Checks if user wants to purge or change status # 3. If viewmode or order isn't given, use the default values.. # 3. Gets todolist 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 => 'todo',language => $config{'language'}); $APPLICATION = $trans->gettext('Personal - Tasks'); %default_secondary_sort = ( DUE_DATE => 'PRIORITY', PRIORITY => 'SUMMARY', SUMMARY => 'PRIORITY', CATEGORY => 'PRIORITY' ); %priority_class = ( 1 => 'todoHighest', 2 => 'todoHigh', 3 => 'todoMedium', 4 => 'todoLow', 5 => 'todoLowest', ); %priority_text = ( 1 => $trans->gettext('Highest'), 2 => $trans->gettext('High'), 3 => $trans->gettext('Medium'), 4 => $trans->gettext('Low'), 5 => $trans->gettext('Lowest'), ); if ($form->{'quit'}) {redirect("$config{'loc_server'}$config{'bin_dir'}/index.html?ID=$form->{'ID'}&auth=$form->{'auth'}&quit=quit");} elsif($form->{'action'}) { if ($form->{'action'} eq 'purge') {purge();} else {change_status();} } if ($form->{'order'} eq undef) {$form->{'order'} = 'DUE_DATE';} if ($form->{'viewmode'} eq undef) {$form->{'viewmode'} = 'incompleted';} print_todo(); print_template("$config{'theme'}_todo"); ########################## # ___ # # ___ | | | \ ___ # # / \ | | | / / \ # # \___ | | |--< \___ # # \ | | | \ \ # # \___/ \__/ |___/ \___/ # # # ########################## ############## # print_todo # # Gets user's todolist 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 todo list and saves it into $todolist # sub print_todo { my ($summary , $info, $priority, $category, $status, $id, @duedate, $duedate, $viewcategory); my (@row); my $task_counter = 0; if ($form->{'viewcategory'} eq 'every' || $form->{'viewcategory'} eq undef) {$viewcategory = '';} elsif ($form->{'viewcategory'} eq 'undefined') {$viewcategory = "AND CATEGORY = ''";} else {$viewcategory = "AND CATEGORY = '".prepare_fordb($form->{'viewcategory'})."'";} lock_tables('READ','todo'); if ($form->{'viewmode'} eq 'all') { db_list("SELECT * FROM todo WHERE USER = '$USER' $viewcategory order by '".prepare_fordb($form->{'order'})."','$default_secondary_sort{$form->{'order'}}'"); } elsif ($form->{'viewmode'} eq 'incompleted') { db_list("SELECT * FROM todo WHERE USER = '$USER' AND STATUS = 1 $viewcategory order by '".prepare_fordb($form->{'order'})."','$default_secondary_sort{$form->{'order'}}'"); } elsif ($form->{'viewmode'} eq 'completed') { db_list("SELECT * FROM todo WHERE USER = '$USER' AND STATUS = 0 $viewcategory order by '".prepare_fordb($form->{'order'})."','$default_secondary_sort{$form->{'order'}}'"); } $todolist .= starttable(width => '95%',align => 'center',cellspacing => 1,cellpadding => 4,gridcolor => 'black'). startrow(bgcolor => "$htmlcolors->{'title'}"); foreach ('',[$trans->gettext('Summary'),'SUMMARY'],[$trans->gettext('Priority'),'PRIORITY'],[$trans->gettext('Category'), 'CATEGORY'],[$trans->gettext('Due date'),'DUE_DATE']) { if ($_ eq undef) { $todolist .= column(class => 'blackTitle',content => html_escape($_).' '); next; } $_->[0] = html_escape($_->[0]); $_->[0] =~ s/ /\ \;/g; $todolist .= column(class => 'blackTitleLink', content => tagged('a',{class => 'blackTitleLink', href => "todo.html?auth=$form->{'auth'}&ID=$form->{'ID'}&order=".encodeurl($_->[1])."&viewmode=".encodeurl($form->{'viewmode'})."&viewcategory=".encodeurl($form->{'viewcategory'}), content => $_->[0].' '})); } $todolist .= endrow(); my (@undefinedtaskrowlist,@definedtaskrowlist); while (my $ref = $sth->fetchrow_hashref()) { $summary = $ref->{'SUMMARY'}; $info = $ref->{'INFO'}; $priority = $ref->{'PRIORITY'}; $category = $ref->{'CATEGORY'}; $status = $ref->{'STATUS'}; $id = $ref->{'ID'}; ($status,$summary,$category,$info) = html_escape($status,$summary,$category,$info); $summary = itag_replacer($summary); $info = itag_replacer($info); $info =~ s/\n/
/gm; $info = $trans->gettext('No description.') unless $info; if (!$category) {$category = $trans->gettext('Undefined');} 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 => "$day_of_month.$month.$year"}); } else {$duedate = "$year/$month/$day_of_month";} } if ($status) { $status = tagged('a',{href => "todo.html?auth=$form->{'auth'}&ID=$form->{'ID'}&action=$id&order=".encodeurl($form->{'order'})."&viewmode=".encodeurl($form->{'viewmode'})."&viewcategory=".encodeurl($form->{'viewcategory'}), content => image(src => "$config{'loc_pictures'}/checkbox.gif", width => 14, height => 14)}); } else { $status = tagged('a',{href => "todo.html?auth=$form->{'auth'}&ID=$form->{'ID'}&action=$id&order=".encodeurl($form->{'order'})."&viewmode=".encodeurl($form->{'viewmode'})."&viewcategory=".encodeurl($form->{'viewcategory'}), content => image(src => "$config{'loc_pictures'}/checkbox_on.gif", width => 14, height => 14)}); } $summary = tagged('a',{onMouseOut => "removeBox()", onMouseOver => "popup('$info')", href => "todo_add.html?auth=$form->{'auth'}&ID=$form->{'ID'}&action=edit&todo=$id&order=".encodeurl($form->{'order'})."&viewmode=".encodeurl($form->{'viewmode'})."&viewcategory=".encodeurl($form->{'viewcategory'}), content => $summary}); my $todorow .= startrow(). column(bgcolor => 'white', width => '1%', class => 'content', content => $status). column(bgcolor => 'white', width => '96%', class => 'contentLink', content => $summary). column(bgcolor => 'white', width => '1%', class => $priority_class{$priority}, content => $priority_text{$priority}). column(bgcolor => 'white', width => '1%', class => 'content', content => $category). column(bgcolor => 'white', width => '1%', class => 'content', content => $duedate). endrow(); if($ref->{'DUE_DATE'}) {push @definedtaskrowlist, $todorow;} else {push @undefinedtaskrowlist, $todorow;} # purkkaa: undefined due date -taskit listaan vikaksi $task_counter++; } push @definedtaskrowlist, @undefinedtaskrowlist; $todolist .= join "", @definedtaskrowlist; $todolist .= startrow(). column(bgcolor => 'white', colspan => '5', class => 'blackTitle', content => $trans->gettext('No tasks.') ). endrow() if !$id; db_end(); unlock_tables(); $todolist .= endtable('hasgrid'); $todolist .= starttable(width => '95%',align => 'center',cellspacing => 3,cellpadding => 2). startrow(). column(class => 'content',align => 'right', content => $trans->gettext('Total number of tasks: '). tagged('b',{content => $task_counter})). endrow(). endtable(); $viewmodebutton = viewmodebutton(); } ############################# # print_template # # Prints 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', 'Tasks', $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 =~ s/<>/$todolist/ms; $fulltemplate =~ s/<>/html_escape($form->{'order'})/gme; $fulltemplate =~ s/<>/html_escape($form->{'viewmode'})/gme; $fulltemplate =~ s/<>/$viewmodebutton/sm; $fulltemplate =~ s/<>/html_escape($form->{'viewcategory'})/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; } ############################ # # change_status # # Changes the status of the todo (incompleted/completed) # # 1. Gets old status from database # 2. Puts new status into database # sub change_status { my(%db); lock_tables('WRITE','todo'); db_list("SELECT STATUS FROM todo WHERE ID ='".prepare_fordb($form->{'action'})."'"); while (my $ref = $sth->fetchrow_hashref()) { if ($ref->{'STATUS'}) {$db{'STATUS'} = 0;} else {$db{'STATUS'} = 1;} } db_end(); db_update("todo",\%db,"ID = '".prepare_fordb($form->{'action'})."'"); db_end(); unlock_tables(); } ######### # purge # # Removes completed todos # sub purge { lock_tables('WRITE', 'todo'); db_delete('todo',"USER = '$USER' and STATUS = '0'"); db_end(); unlock_tables(); } ################### # viewmodebutton # # Forms the god dääm funky viewmodebutton # sub viewmodebutton { my ($viewmodebutton, @categories); my @viewmodes = ('all', 'incompleted', 'completed'); @viewmodes = grep {$_ ne $form->{'viewmode'}} @viewmodes; foreach (@viewmodes) { $_ = tagged('a', {href => "todo_add.html?auth=$form->{'auth'}&ID=$form->{'ID'}&order=".encodeurl($form->{'order'})."&viewmode=$_&viewcategory=".encodeurl($form->{'viewcategory'}), content => image(align => "absmiddle", src => "$config{'loc_pictures'}/$_.gif")}); } $viewmodebutton = join " / ", @viewmodes; my $categorybutton = tag('select', {name => 'viewcategory', onChange => 'return change_view();'}); if ('every' eq $form->{'viewcategory'}) { $categorybutton .= tagged('option',{value => "todo.html?auth=$form->{'auth'}&ID=$form->{'ID'}&order=".encodeurl($form->{'order'})."&viewmode=".encodeurl($form->{'viewmode'})."&viewcategory=every", content => $trans->gettext('Every')}, 'selected'); } else { $categorybutton .= tagged('option',{value => "todo.html?auth=$form->{'auth'}&ID=$form->{'ID'}&order=".encodeurl($form->{'order'})."&viewmode=".encodeurl($form->{'viewmode'})."&viewcategory=every", content => $trans->gettext('Every')}); } if ('undefined' eq $form->{'viewcategory'}) { $categorybutton .= tagged('option',{value => "todo.html?auth=$form->{'auth'}&ID=$form->{'ID'}&order=".encodeurl($form->{'order'})."&viewmode=".encodeurl($form->{'viewmode'})."&viewcategory=undefined", content => $trans->gettext('Undefined')}, 'selected'); } else { $categorybutton .= tagged('option',{value => "todo.html?auth=$form->{'auth'}&ID=$form->{'ID'}&order=".encodeurl($form->{'order'})."&viewmode=".encodeurl($form->{'viewmode'})."&viewcategory=undefined", content => $trans->gettext('Undefined')}); } lock_tables('READ', 'todo'); db_list("SELECT DISTINCT category FROM todo WHERE USER = '$USER' order by category"); while (my $ref = $sth->fetchrow_hashref()) { next if ($ref->{'category'} eq ''); push @categories, $ref->{'category'}; } db_end(); unlock_tables(); foreach (@categories) { if ($_ eq $form->{'viewcategory'}) { $categorybutton .= tagged('option',{value => "todo.html?auth=$form->{'auth'}&ID=$form->{'ID'}&order=".encodeurl($form->{'order'})."&viewmode=".encodeurl($form->{'viewmode'})."&viewcategory=".encodeurl($_), content => html_escape($_)}, 'selected'); } else { $categorybutton .= tagged('option',{value => "todo.html?auth=$form->{'auth'}&ID=$form->{'ID'}&order=".encodeurl($form->{'order'})."&viewmode=".encodeurl($form->{'viewmode'})."&viewcategory=".encodeurl($_), content => html_escape($_)}); } } $categorybutton .= tag('/select'); return tagged('span', {class => 'content', content => $trans->gettext("View ")."  ${viewmodebutton}  ". sprintf($trans->gettext("todos in %s - category"),$categorybutton) }); }