#! /usr/bin/perl use Tie::File; # # Todo Issues - A task manager/tracker of things to do. # Kirk Waingrow (c) 8/2003 - V2.0 # # 2.9 - Added Display by owner, Due date was added. # 2.8 - fixed index numbering, fixed new updates display, reformat add/modify pages. # "ISSUES" changed to "ITEMS" # 2.7 - Removed Days, Added New Move routing, Added "Update & Close" # # Reference with http://blah.blah.com/cgi-bin/todo?ID=tva # Where ID equals the list name that everything is create under. # Make sure there is a $WEBPATH.loc for locations datafile # and a $WEBPATH.ass for assignments file. # # $VERSION="3.0 - Oct 14, 2007"; $EMAIL="admins"; $LINK="http://tvasandbox"; # http address $WEBPATH="/cgi-bin/todo"; # CGI path $HPATH="/httpd"; # location of http for html/cgi $DPATH="$HPATH/html/todo"; # Path to Data $TRUDATE=`date '+%B %d, %Y / %H:%M:%S - %A'`; chop($TRUDATE); $DATE=`date +%y%m%d%H%M%S`; chop($DATE); $YMDHMS=`date '+%y.%m.%d-%H.%M.%S'`; chop($DT); $DT=`date '+%y.%m.%d'`; chop($DT); $ID=""; print "Content-type: text/html\n\n"; print "Issues To Track\n"; print "\n"; $buffer = "$QUERY_STRING"; $buffer = $ENV{'QUERY_STRING'}; $REMOTEADDR = $ENV{'REMOTE_ADDR'}; #$REMOTEADDR = "192.168.1.105"; @pairs = split (/&/, $buffer); # Create the array foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $form{$name} = $value; #print "$form{$name} "; if ( $name eq "ID" ) { $ID=$form{ID}; } } if ( ! $ID ) { print "YOU NEED A ITEMS LIST ID\n" ; exit;} if ($form{OWNER} ) { $form{search}="$form{OWNER}" } #if ( "$form{search}" ) { $form{print}="1"; } ### ### #Set up for a print page ### if ( ! "$form{PRN}" ) { $print="&PRN=1"; } else { $print=""; } if ( ! "$form{PRN}" ) { &display_header_bar; } $OPEN="$DPATH/$ID/open"; $CLOSE="$DPATH/$ID/close"; $TODO="$DPATH/$ID"; if ( ! -d "$DPATH/$ID" ) { `mkdir -p $DPATH/$ID`; } `touch $OPEN $CLOSE`; if ( ! -d "$DPATH/$ID/viewed" ) { `mkdir -p $DPATH/$ID/viewed`; } # Collect what the user has viewed if ( ! -f "$DPATH/$ID/viewed/$REMOTEADDR" ) { `touch $DPATH/$ID/viewed/$REMOTEADDR`; } open(infile, "$DPATH/$ID/viewed/$REMOTEADDR") || print "$DPATH/$ID/viewed/$REMOTEADDR Not here"; while () { push(@userlist, $_); } close(infile); ### ### If "Update and Close" is pressed, pass $form{REM}=1 to Close issue ### if ( $form{CLOSE} ) { $form{REM}=1; } ## ## MOVE RECORDS FROM/TO ## if ( $form{RecFROM} && $form{RecTO} ) { tie @OPEN, 'Tie::File', "$OPEN" or die; # FIND THE FROM RECORD $COUNT=0; foreach (@OPEN) { $COUNT++; if ( $COUNT == $form{RecFROM} ) { $FROM="$_"; } } $COUNT=0; foreach (@OPEN) { $COUNT++; if ( $COUNT == $form{RecFROM} ) { $DONOTHING=""; } else { if ( $COUNT == $form{RecTO} ) { push(@NEW,"$FROM"); } push(@NEW, "$_"); } } @OPEN=@NEW; untie(@OPEN); } ## ## WRITE NEW ITEM TO INDEX ## if ( $form{AF} ) { if ( $form{TI}) { $FOUND=""; open (addfile, ">> $OPEN.tmp") || print "Cant open $OPEN.tmp"; if ( ! -s $OPEN) { print addfile "$form{PRI}\t$form{IDX}\t$form{TI}\t$DT\t$form{LOC}\t$form{OWN}\t$form{DYS}\n"; } else { open (infile, "$OPEN") || print "Cant open $OPEN"; while () { ($PRI, $d1, $d2, $d3, $d4, $d5,$d6) = split ("\t", $_); if ( $PRI eq $form{PRI} && ! $FOUND ) { print addfile "$form{PRI}\t$form{IDX}\t$form{TI}\t$DT\t$form{LOC}\t$form{OWN}\t$form{DYS}\n"; $FOUND="1"; } if ( $form{PRI} < $PRI && ! $FOUND ) { print addfile "$form{PRI}\t$form{IDX}\t$form{TI}\t$DT\t$form{LOC}\t$form{OWN}\t$form{DYS}\n"; $FOUND="1"; } print addfile "$_"; } close(infile); if ( ! $FOUND ) { print addfile "$form{PRI}\t$form{IDX}\t$form{TI}\t$DT\t$form{LOC}\t$form{OWN}\t$form{DYS}\n"; $FOUND="1"; } } close(addfile); #`sort -n $OPEN > $OPEN.tmp`; `mv $OPEN.tmp $OPEN`; # # Create record Directory # if ( ! -d "$TODO/$form{IDX}" ) { `mkdir $TODO/$form{IDX}`; } open (addfile, "> $TODO/$form{IDX}/.$form{IDX}_idx") || print "Cant open $TODO/$form{IDX}.idx"; print addfile "$form{PRI}\t$form{IDX}\t$form{TI}\t$DT\t$form{LOC}\t$form{OWN}\t$form{DYS}\n"; close(addfile); open (addrec, "> $TODO/$form{IDX}/$form{IDX}-$YMDHMS") || print "Cant open $TODO/$form{IDX}/$form{IDX}.$YMDHMS"; if ($form{DSC} || $form{DSC2}) { print addrec "$TRUDATE\n"; } if ( $form{DSC}) { print addrec "$form{DSC}\n"; } if ( $form{DSC2}) { print addrec "$form{DSC2}\n"; } close(addrec); $MESS="OI-NEW:$form{PRI}"; &send_email; } else # IF NO TITLE IS ENTERED GO BACK TO THE ADD ITEM PAGE { $form{ADD}=1; } } # # MODIFY AN EXISTING ITEM # if ( $form{MF} ) { open (outfile, "> $OPEN.tmp"); open (infile, "$OPEN"); while () { if ( /$form{IDX}/ ) { ($PRI, $TIME, $LINE, $PDATE, $LOC, $OWN, $DYS) = split ("\t", $_); print outfile "$form{PRI} $form{IDX} $form{TITLE} $PDATE $form{LOC} $form{OWN} $form{DYS}\n"; } else { print outfile "$_"; } } close(infile); close(outfile); `mv $OPEN.tmp $OPEN`; #`sort -n $OPEN.tmp > $OPEN.tmp2`; #`mv $OPEN.tmp2 $OPEN`; #`rm -f $OPEN.tmp`; # MAKE CHANGES TO THE ITEMS FILE if ( $form{DSC} || $form{DSC2}) { if ( $form{DSC}) { open (addfile, ">> $TODO/$form{IDX}/$form{IDX}-$YMDHMS") || print "=$TODO/$form{IDX}/$form{IDX}-$YMDHMS"; print addfile "$TRUDATE\n"; print addfile "$form{DSC}\n"; close(addfile); } else { open (addfile, "> $TODO/$form{IDX}/$form{IDX}-$YMDHMS"); print addfile "$TRUDATE\n"; print addfile "$form{DSC2}\n"; } close(addfile); { $MESS="OI-UPDATE:$form{PRI}"; &send_email; } } open (listIP, "ls -1 $DPATH/$ID/viewed |" ); while () { chomp; if ( "$_" ne "$REMOTEADDR" ) { `grep -v $form{IDX} $DPATH/$ID/viewed/$_ > $DPATH/$ID/viewed/$_.tmp`; `mv $DPATH/$ID/viewed/$_.tmp $DPATH/$ID/viewed/$_`; } } close(listIP); } ## ## IF A PRIORITY LEVEL IS CHANGED ## #if ( $form{NP} ) #{ # open (outfile, "> $OPEN.tmp"); # open (infile, "$OPEN"); # while () # { # if ( /\t$form{IDX}\t/ ) # { # ($PRI, $TIME, $LINE, $PDATE, $LOC, $OWN,$DYS) = split ("\t", $_); # print outfile "$form{NP} $TIME $LINE $PDATE $LOC $OWN $DYS"; # } # else # { print outfile "$_";} # } # close(infile); # close(outfile); # #`sort -n $OPEN.tmp > $OPEN.tmp2`; # #`mv $OPEN.tmp2 $OPEN`; # #`rm -f $OPEN.tmp`; #} ## ## IF TASK IS BEING CLOSED ## if ( $form{REM} ) { open (outfile, "> $OPEN.tmp") || print "$OPEN.tmp problem"; open (infile, "$OPEN") || print "$OPEN.tmp problem"; while () { if (! /\t$form{"IDX"}\t/ ) { print outfile "$_";} else { open (closefile, ">> $CLOSE"); print closefile "$_"; close(closefile); } } close(infile); close(outfile); `mv $OPEN.tmp $OPEN`; $MESS="OI-CLOSED"; &send_email; } ## ## IF TASK IS BEING RE-OPENED ## if ( $form{REOP} ) { open (outfile, "> $CLOSE.tmp"); open (infile, "$CLOSE"); while () { if (! /\t$form{"IDX"}\t/ ) { print outfile "$_";} else { open (openfile, ">> $OPEN"); print openfile "$_"; close(openfile); } } close(infile); close(outfile); `mv $CLOSE.tmp $CLOSE`; #`sort -n $OPEN > $OPEN.tmp`; #`mv $OPEN.tmp $OPEN`; $MESS="OI-REOPEN"; &send_email; } ## ## DISPLAY OPEN OR CLOSED INDEX ## if ( $form{OC} ) { if ($form{"OC"} eq "O") { $FILE="$TODO/open"; $TYPE="OPEN"; # # MARK EVERYTHING READ # open (outfile, ">> $DPATH/$ID/viewed/$REMOTEADDR"); open(infile, "$OPEN"); while () { ($PRI, $TIME, $LINE, $PDATE,$LOC,$OWN,$DYS) = split ("\t", $_); print outfile "$TIME\n"; } close(infile); close(outfile); $COLOR="e8e8e8"; } else { $FILE="$TODO/close"; $TYPE="CLOSED"; $COLOR="ffffff"; } $reccnt=0; open (infile, "$FILE"); while () { $reccnt++; } close(infile); #print "
$reccnt $TYPE ITEMS

\n"; print "

$reccnt $TYPE ITEMS TRACKED "; print "

\n"; print "\n"; $TOTAL=1; $CCOLOR="ffffff"; open(infile, "$FILE"); while () { ($PRI, $TIME, $LINE, $PDATE, $LOC, $OWN,$DYS) = split ("\t", $_); print "\n"; } if ($form{"OC"} eq "O") { # Find the last entry file for the record print ""; $TOTAL++; } close(infile); print "
$TOTAL)\n"; if ( $PRI == 1 ) { $BGC="\"HIGH"; } if ( $PRI == 2 ) { $BGC="\"MEDIUM"; } if ( $PRI == 3 ) { $BGC="\"LOW"; } if ( $TYPE eq "OPEN" ) { print "$BGC\n"; print "$LINE - $PDATE - Due $DYS / $LOC / $OWN\n"; } else { if ( $CCOLOR eq "ffffff" ) { $CCOLOR="e8e8e8"; } else { $CCOLOR="ffffff"; } print "$BGC\n"; print "$LINE - $PDATE - Due $DYS / $LOC / $OWN\n"; print "reopen
\n"; open (listdir, "ls -1 $TODO/$form{IDX}/$TIME| tail -1|"); while () { chomp; $FILEIDX="$_"; } close(listdir); # Open the last entry made $cnt=0; open(DATAFILE, "$TODO/$form{IDX}/$TIME/$FILEIDX") || print "- $TODO/$form{IDX}/$FILEIDX"; while () { if ( $cnt == 0 ) { print "$_
\n"; } else { print "$_
\n"; } $cnt++; } close(DATAFILE); } print " 

\n"; # print "

"; # print "

"; # print "

\n"; print "


"; exit; } if ( $form{CV} ) { # Get index file entry open (DATAFILE, "$TODO/$form{IDX}/.$form{IDX}_idx"); while () { ($PRI, $TIME, $LINE, $PDATE,$LOC,$OWN,$DYS) = split ("\t", $_); } if ( $PRI == 1 ) { $chk1="checked"; $bgc="red";} if ( $PRI == 2 ) { $chk2="checked"; $bgc="yellow";} if ( $PRI == 3 ) { $chk3="checked"; $bgc="lightblue";} close(DATAFILE); print qq~
CLOSED - $LINE
DUE DATE:
Location:
Assign To:
$DYS
$LOC
$OWN

~; &display_records; print "
"; exit; } # # ADD A NEW ENTRY # if ( $form{ADD} ) { print qq~
CREATE ITEM


\n"; if ( ! $form{TI} && $form{AF} ) { $TIERROR="ERROR: MUST ENTER A TITLE"; } else { $TIERROR=""; } print qq~
 New Title: $TIERROR  $form{TI}
 
Priority: 1 - High 2 - Medium 3 - Low
Location:
Due Date:
Assign To:
 Complete Description:
 
Email Notification:          
~; exit; } # # DISPLAY AN ENTRY AND MODIFY FORM # if ( $form{DREC} ) { # Add IDX to mark a record has not been read open (outfile, ">> $DPATH/$ID/viewed/$REMOTEADDR"); print outfile "$form{IDX}\n"; close(outfile); $chk1=""; $chk2=""; $chk3=""; open(infile, $OPEN); while () { chomp; if ( /$form{IDX}/ ) { ($PRI, $TIME, $LINE, $PDATE,$LOC,$OWN,$DYS) = split ("\t", $_); } } close(infile); # GET WHICH PRIORITY IS SET TO if ( $PRI == 1 ) { $chk1="checked"; $bgc="red";} if ( $PRI == 2 ) { $chk2="checked"; $bgc="yellow";} if ( $PRI == 3 ) { $chk3="checked"; $bgc="lightblue";} print qq~
$LINE
DUE DATE:
Location:
Assign To:
$DYS
$LOC
$OWN

~; # DISPLAY EACH RECORD FILE FOR AN ITEM &display_records; print "
 

 "; if (! $form{MOD} && ! $form{PRN}) { # Display Modify form print qq~

\n"; print qq~
 Title:  
Priority: 1 - High 2 - Medium 3 - Low
  Location: Days:   Assign To:
 Add A Full Description:
Email Notification:                
~; } exit; } $reccnt=0; open (infile, "$OPEN"); while () { if ( $form{search} ) { if ( /$form{search}/i ) {$reccnt++;} } else { $reccnt++; } } close(infile); ## ## DISPLAY THE ITEMS LIST ## print qq~
$reccnt OPEN ITEMS TRACKED ~; if ( $form{OWNER} ) { print "FOR $form{OWNER}"; } print qq~ Search: or \n"; print qq~

~; print qq~ ~; @userlist=""; open(infile, "$DPATH/$ID/viewed/$REMOTEADDR") || print "$DPATH/$ID/viewed/$REMOTEADDR Not here"; while () { push(@userlist, $_); } close(infile); $bs=0; $LC=0; $EOF=`wc -l $OPEN | awk '{ print $1}'`; $reccnt=0; open(infile, "$OPEN"); while () { $LC++; ($PRI, $TIME, $LINE, $PDATE,$LOC,$OWN,$DYS) = split ("\t", $_); # $NEW="\*"; $NEW=""; foreach(@userlist) { if ( /$TIME/ ) { $NEW=""; } } $FOUNDsearch=""; if ( "$form{search}" ) { if ( /$form{search}/i ) { $FOUNDsearch="1"; print "\n";} if ( $form{OWNER} ) { if ( $form{OWNER} eq "$OWN" ) { $FOUNDsearch="1"; } else { $FOUNDsearch=""; } } } else { $FOUNDsearch="1"; print "\n"; } if ( $PRI == 1) { $BGC="\"HIGH"; } if ( $PRI == 2) { $BGC="\"MEDIUM"; } if ( $PRI == 3) { $BGC="\"LOW"; } if ( $FOUNDsearch ) { if ( ! "$form{print}" ) { #print "\n"; } $reccnt++; if ( $reccnt < 10 ) { $spc=" "; $zero="0";} else {$spc=" "; $zero="";} print ""; if ( $bs == 1 ) { $bcs="white"; $bs=0; } else { $bcs="e8e8e8"; $bs=1; } print qq~ ~; } } if ( ! "$form{print}" ) { print "
Active Issue
Date Created
Due Date
Location
Owner
\n"; #print "\n"; #print "\n"; ##print "\"CLOSE\n"; #print "${zero}$reccnt $spc $BGC $spc $LINE $NEW $PDATE $DYS $LOC $OWN

\n"; #print "
\n"; #print "\n"; #print "\n"; } print "\n"; print "
Version: $VERSION
"; # DISPLAY HEADER BAR sub display_header_bar { if ( ! "$form{print}" ) { print qq~
~; if ( ! $form{search} && ! $form{MOD} && ! $form{ADD} && ! $form{DREC} && ! $form{CV} && ! $form{OC}) { print qq~ ~; } # } print "
LIST ITEMS OPEN ITEMS CREATE ITEM PRINTER CLOSED ITEMS From: To:

"; } #end sub # DISPLAY ALL RECORDS IN AN ITEM sub display_records { print "\n"; open (infile, "ls -1r $TODO/$form{IDX}|"); while () { $ccnt=0; open (inrecord, "$TODO/$form{IDX}/$_"); while () { chomp; $ccnt++; if ( $ccnt == 1 ) { print "\n"; print "\n"; } close(infile); print "
$_
";
        }
        else { print "$_"; }
      }
      close(inrecord);
      print "
 
\n"; } ## ## MAIL OUT NOTIFICATION ## sub send_email { if ( "$form{EM}" ) { $mail_prog = "/usr/lib/sendmail"; if ( $form{REM} ) {open (infile, "$CLOSE"); } else {open (infile, "$OPEN"); } while () { if ( /$form{IDX}/ ) {($PRI, $TIME, $LINE, $PDATE, $LOC, $OWN,$DYS) = split ("\t", $_); } } close(infile); #print "$form{IDX} - LINE=$LINE
"; open (MAIL, "|$mail_prog $EMAIL") || die "Could not open $mail_prog"; print MAIL "From: support\n"; print MAIL "Reply-to: support\n"; print MAIL "Subject: $MESS: $LINE\n"; # Create Doc print MAIL "\n\n Issue: $LINE\n"; print MAIL " Created: $PDATE\n"; print MAIL " Priority: $PRI\n"; print MAIL " Location: $LOC\n"; print MAIL " Owner: $OWN\n"; if ( $form{REM} ) {print MAIL "\n LINK: $LINK$WEBPATH?ID=tva&CV=1&IDX=$form{IDX}\n\n"; } else { print MAIL "\n LINK: $LINK$WEBPATH?ID=tva&DREC=1&IDX=$form{IDX}\n\n"; } print MAIL "LAST UPDATE:\n\n$form{DSC2}\t($DT)\n"; print MAIL "\n\n\n\n\n"; print "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n\n\n\n\n"; # print MAIL "THE ENTIRE BODY WAS UPDATED:\n\n"; # open (IN, "$TODO/$TIME"); # while () # { print MAIL "$_"; } # close(IN); print MAIL ".\n"; close(MAIL); } }