#!/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: todosync.html,v 1.6 2002/06/06 14:58:02 inf Exp $ ##################################################### # # # Synchronize Pam Todo database with mimerdesk # # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # # (c) Ionstream Oy 1999 - 2001 # # # # Programmed by: Teemu Arina # # # ##################################################### # Asetukset ################################## use strict; use vars qw ($APPLICATION $ACTIVEGRP $USER $IP $LAST_ACT $trans $FORWARDED $TIME_USED $IDLE $form $ref $sth); use lib::MimerDesk; use Palm::PDB; use Palm::ToDo; use Palm::StdAppInfo; sub print_template; sub import_tasks; sub export_tasks; $APPLICATION = 'Personal - Tasks'; # 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 => 'handheldsync',language => $config{'language'}); $APPLICATION = $trans->gettext('Personal - Tasks'); if ($form->{'quit'}) {redirect("$config{'loc_server'}$config{'bin_dir'}/index.html?ID=$form->{'ID'}&auth=$form->{'auth'}&quit=quit");} elsif ($form->{'importtasks'}) { if (!$form->{'filename'}) {print_template("$config{'theme'}_sync", $trans->gettext('You must select a file to import/upload!'),'error');} my ($messages,$colorclass) = import_tasks($form->{'filename'}); unlink($form->{'filename'}); print_template("$config{'theme'}_sync", $messages,$colorclass); } elsif ($form->{'showexport'}) {print_template("$config{'theme'}_todopalmimport");} elsif ($form->{'exporttasks'}) {export_tasks();} else {print_template("$config{'theme'}_sync");} ################################## # Read template and process it # ################################## sub print_template { my ($ref,$fulltemplate); my ($template,$messages,$colorclass) = @_; print_header('pragma'); $ref = get_template('maintemplate',$template); $ref->{'maintemplate'} =~ s/<>/$ref->{$template}/m; $fulltemplate = $ref->{'maintemplate'}; $ref = get_template('js_doClock', 'js_help', 'js_gotosite'); my $stuff = join "", ($ref->{'js_doClock'},$ref->{'js_help'},$ref->{'js_gotosite'}); $fulltemplate =~ s/<>/$stuff/ms; $fulltemplate = create_buttons($fulltemplate, 'Personal', 'Tasks', $form); $fulltemplate =~ s/<>/minea/gm; $fulltemplate =~ s/<>/MimerDesk\: $APPLICATION/ms; $fulltemplate = replace_tags($fulltemplate, $USER, $form->{'auth'}, $form->{'ID'}, $TIME_USED); $fulltemplate = add_popups($fulltemplate, $USER, $form->{'auth'}, $form->{'ID'}); $fulltemplate =~ s/<>/$messages/m; $fulltemplate =~ s/<>/$colorclass/m; print $fulltemplate; db_end('disconnect'); exit; } ################ # Import tasks # ################ sub import_tasks { my ($messages,$countrecords,$duedate,$status,%categories,@todos,$todorecord); my $skipped = '0'; my $filename = shift; my $pdb = new Palm::PDB; eval '$pdb->Load($filename)' or return (sprintf($trans->gettext("File %s has no records!"),$form->{'filename','tiedostonimi'}),'error'); return (sprintf($trans->gettext("File %s is a wrong pdb file!"),$form->{'filename','tiedostonimi'}),'error') if $pdb->{"creator"} ne 'todo'; foreach my $cat (@{$pdb->{'appinfo'}{'categories'}}) { $categories{$cat->{'id'}} = $cat->{'name'}; } $messages = sprintf($trans->gettext("Importing file %s..."),$form->{'filename','tiedostonimi'}). tag('br'). tag('br'); my ($sec,$min,$hour,$day_of_month,$month,$year) = utc_epoch2date($pdb->{'ctime'}); $messages .= "Created: $hour:$min:$sec $day_of_month.$month.".($year).tag('br'); my ($sec,$min,$hour,$day_of_month,$month,$year) = utc_epoch2date($pdb->{'mtime'}); $messages .= "Modified: $hour:$min:$sec $day_of_month.$month.".($year).tag('br'); my ($sec,$min,$hour,$day_of_month,$month,$year) = utc_epoch2date($pdb->{'baktime'}); $messages .= "Backup: $hour:$min:$sec $day_of_month.$month.".($year).tag('br').tag('br'); eval '$countrecords = @{$pdb->{\'records\'}}' or return (sprintf($trans->gettext("File %s has no records!"),$form->{'filename','tiedostonimi'}),'error'); lock_tables('WRITE','todo'); db_list("SELECT SUMMARY FROM todo WHERE USER = '$USER'"); while (my $ref = $sth->fetchrow_hashref()) {push @todos, $ref->{'SUMMARY'};} db_end(); foreach my $record (@{$pdb->{'records'}}) { $todorecord = { PRIORITY => $record->{'priority'}, SUMMARY => $record->{'description'}, CATEGORY => $record->{'category'}, INFO => $record->{'note'}, USER => $USER, STATUS => $status, DUE_DATE => $duedate }; if ($record->{'due_day'}) { $duedate = local_date2utc_epoch(undef,undef,undef,$record->{'due_day'}+1,$record->{'due_month'},$record->{'due_year'}); } if (!$record->{'completed'}) {$status = '1' ;} else {$status = '0';} if (!$record->{'category'}) {$record->{'category'} = undef;} else {$record->{'category'} = $categories{$record->{'category'}};} if (grep {$_ eq $record->{'description'}} @todos) { db_update('todo', $todorecord, "SUMMARY = '$record->{'description'}'"); $countrecords--; $skipped++; } else {db_insert('todo', $todorecord);} } unlock_tables(); $messages .= sprintf($trans->gettext("Imported %d new records into database."),$countrecords); $messages .= ' '.sprintf($trans->gettext("Updated %d records."),$skipped) if $skipped; return ($messages,'success'); } ################ # Export tasks # ################ sub export_tasks { my (@categories,$category); my $catid = '0'; my $pdb = new Palm::ToDo; my $record = $pdb->new_Record(); lock_tables('READ','todo'); db_list("SELECT * FROM todo WHERE USER = '$USER'"); while (my $ref = $sth->fetchrow_hashref()) { $category = '0'; $record = new_Record Palm::PDB; (undef,undef,undef,$record->{'due_day'},$record->{'due_month'},$record->{'due_year'}) = utc_epoch2date($ref->{'DUE_DATE'}) if $ref->{'DUE_DATE'}; if ($ref->{'CATEGORY'} && !(grep {$_ eq $ref->{'CATEGORY'}} @categories)) { $catid++; $pdb->addCategory($ref->{'CATEGORY'}, $catid); push @categories, $ref->{'CATEGORY'}; $category = $catid; } $record->{'description'} = $ref->{'SUMMARY'}; $record->{'note'} = $ref->{'INFO'}; $record->{'priority'} = $ref->{'PRIORITY'}; $record->{'category'} = $category; if (!$ref->{'STATUS'}) {$record->{'completed'} = '1' ;} else {$record->{'completed'} = '0';} $pdb->append_Record($record); } db_end(); unlock_tables(); $pdb->Write("${USER}tasks.pdb"); print "Content-Type: application/octet-stream\n"; print "Content-Disposition: attachment; filename=ToDoDB.pdb\n\n"; open FILE, "<${USER}tasks.pdb" or write_log("Error opening file ${USER}tasks.pdb", 'error'); print while ; close FILE; unlink("${USER}tasks.pdb"); exit; }