#!/usr/bin/perl ############################################################################ # # Copyright 1999-2002 Openwave Systems Inc. All rights reserved. # # Subject to the terms and conditions of the SDK License Agreement, # Openwave Systems Inc. hereby grants you the right to use the UP.SDK # software and its related documentation. # # The Openwave Systems name and logo and the family of terms carrying # the "UP." prefix are trademarks of Openwave Systems Inc. All other # trademarks and registered trademarks are the properties of their # respective owners. # ############################################################################ ###################################################################### # # This version builds upon todo1.cgi by adding some TTL elements. # ###################################################################### ###################################################################### # AppUtils Loading and Configuration ###################################################################### # # We add various paths to the @INC array since this program is a # part of multiple products including the SDK # push (@INC, "../apputils"); # # Load required application utilities # require 'HTTPClient.pl'; require 'DeckUtils.pl'; require 'FileUtils.pl'; require 'Digest.pm'; require 'todoData.pm'; ###################################################################### # Constants ###################################################################### # # The HDML Cards # $TODOLIST = '

Todo:

'; $TODOENTRY = '

'; $STATUSCHOICE = '

'; $EMPTYFINISHED = '

Finished Items:
[Empty]

'; $FINISHEDLIST = '

Finished Items:

'; $DESCNEEDED = '

You must enter a description.

'; $CONFIRMDEL = '

Clear all finished?

'; # State definitions # # Static states {state, deck} %StaticStateArray = ( "NEW", $TODOENTRY, "STATUS", $STATUSCHOICE, "CONFIRMDEL", $CONFIRMDEL ); # Dynamic states {state, routine} %DynamicStateArray = ( "TODOLIST", "TodoList", "SAVENEW", "SaveNewTodo", "SETSTATUS","SetStatus", "FINISHED", "FinishedItems", "ERASEFINISHED", "EraseFinishedItems" ); ###################################################################### # MAIN Function # # Get all out http vars into cgiVars # ###################################################################### # # Parse the CGI variables into the associative array %cgiVars # %cgiVars = &AppUtils::ParseCGIVars(); $Subscriber = $ENV{'HTTP_X_UP_SUBNO'}; # Get a db object $todoData = TodoData->New($Subscriber); # # Get the next state and look it up # $nextState = $cgiVars{"NS"}; if( !defined($nextState) ) { $nextState = "TODOLIST"; } # # Transition to the next state # $deck = $StaticStateArray{$nextState}; if( $deck ne "" ) { my $digest = new Digest; $digest->addDeck("", $deck); &AppUtils::OutputDigest($digest->asString); } else { $subRoutine = $DynamicStateArray{$nextState}; if ($subRoutine ne undef) { # this is a subroutine call. &$subRoutine(); } else { &AppUtils::ErrorExit("Invalid URL", ""); } } sub TodoList { my @todoItems = $todoData->GetActiveItems(); my %item; my $choices; my $status; my $text; foreach(@todoItems) { %item = %$_; $status = $item{'status'}; $text = $item{'text'}; $choices .= ""; } if ($choices eq "") { $choices = ""; } my $digest = new Digest; $digest->addDeck("", sprintf($TODOLIST, $choices)); &AppUtils::OutputDigest($digest->asString); } sub SaveNewTodo { my $desc = $cgiVars{'desc'}; if ($desc eq "") { my $digest = new Digest; $digest->addDeck("", $DESCNEEDED); &AppUtils::OutputDigest($digest->asString); return; } # Save the new entry $todoData->InsertNewItem($desc); # Redisplay the todo list &TodoList(); } sub SetStatus { my $index = $cgiVars{'index'}; my $status = $cgiVars{'sts'}; # Set the status $todoData->SetStatus($index, $status); # Redisplay the todo list &TodoList(); } sub FinishedItems { my @todoItems = $todoData->GetFinishedItems(); my %item; my $choices; my $status; my $text; foreach(@todoItems) { %item = %$_; $status = $item{'status'}; $text = $item{'text'}; $choices .= "$text "; } my $digest = new Digest; if ($choices eq "") { $digest->addDeck("", $EMPTYFINISHED); } else { $digest->addDeck("", sprintf($FINISHEDLIST, $choices)); } &AppUtils::OutputDigest($digest->asString); } sub EraseFinishedItems { # Set the status $todoData->DeleteFinishedItems(); # Redisplay the todo list &TodoList(); }