#!/usr/bin/perl
#
# Tag file based actions cgi scripts
#
# John Lines (john@paladin.demon.co.uk)
# Version 1.0 2-Nov-1996
# Version 1.1 20-Apr-1997 - start to use CGI.pm
# Version 1.2 20-May-1997 - automatic sequence numbering
# Version 1.3 3-Jul-1997 - information about an actions file
# Version 1.4 8-Dec-1998 - look for configuration in several
# places
#
use CGI qw(:standard);
use File::Basename;
$ENV{PATH}='';
$version="1.4";
$cat="/bin/cat";
# The following variables can be set by an included configuration file
$site_version="1.0";
$tagbindir="/usr/bin";
$actions_dir="/usr/lib/tag/actions";
$actions_file="$actions_dir/default.act";
if (-r "actions-site.pl" ) { require "actions-site.pl" ; }
elsif ( -r "/etc/tag/actions-site.pl" ) { require "/etc/tag/actions-site.pl"; }
#$actions_dir="/home/john/diary/actions";
#$actions_file="$actions_dir/default.act";
$|=1;
print header;
# print "Content-type: text/html\n\n";
($dummy,$command,$cmdarg,$cmdarg1) = split(/\//,$ENV{'PATH_INFO'});
if ($command eq "") {
# give them the options
print "Use as /cgi-bin/actions/display/actions-file.act
where actions-file.act is a tag format actions file\n";
print "
\n"; print "About this script\n"; print start_form; # Find possible file names chdir($actions_dir); opendir(ACTIONDIR,".") || print "Could not open directory $actions_dir\n" ; @textfiles=grep -T,readdir(ACTIONDIR); closedir(ACTIONDIR); @textfiles=('',@textfiles); print "Action file ",popup_menu('filename',\@textfiles,''),br; print "State ",checkbox(-name=>'Pending',-checked=>'checked',-label=>'Pending'); print checkbox(-name=>'Active',-checked=>'checked',-label=>'Active'); print checkbox(-name=>'Completed',-checked=>'checked',-label=>'Completed'); print br; print "Display as ",radio_group(-name=>'DisplayAs',-values=>[List,Table,Raw],-default=>'List'); print p,submit,end_form,p; if (param) { $p_filename=param('filename'); $p_filename =~ /^([\w.]*)$/; $p_filename=$1; $tagfilename="$actions_dir/$p_filename"; $p=param('Pending'); $p =~ /^([\w]*)$/; $p=$1; $show_pending=""; $show_pending=" | $tagbindir/tagextract -v -m Status -eq Pending " if ($p ne "on" ); $p=param('Active'); $p =~ /^([\w]*)$/; $p=$1; $show_active=""; $show_active=" | $tagbindir/tagextract -v -m Status -eq Active " if ($p ne "on" ); $p=param('Completed'); $p =~ /^([\w]*)$/; $p=$1; $show_completed=""; $show_completed=" | $tagbindir/tagextract -v -m Status -eq Completed " if ($p ne "on" ); $p_disp=param('DisplayAs'); $p_disp =~ /^([\w]*)$/; $p_disp=$1; if ($p_disp eq "Table") { $display_cmd="| $tagbindir/tag2html -o border -t Id Title"; } elsif ($p_disp eq "List") { $display_cmd="| $tagbindir/tag2html"; } elsif ($p_disp eq "Raw") { # for the moment we will just write it out as preformatted text, would like # to do something more useful here - such as switch mime types print "
\n";
$display_cmd="";
}
if ( -r $tagfilename ) {
system("$cat $tagfilename $show_pending $show_active $show_completed $display_cmd");
}
}
exit;
}
if ($command eq "about") {
print "About actions \n";
print "About actions
\n";
print "Actions was written by John Lines\n";
print "This is version $version\n
";
print "For the latest version see the tag types web page\n";
print "in particular the actions section\n";
print "
\n";
print "\n";
exit;
}
if ($command eq "display") {
if ($cmdarg eq "") {
print "
Actions directory index \n";
print "Actions directory
\n";
chdir($actions_dir);
opendir(ACTIONDIR,".") || print "Could not open directory $actions_dir\n" ;
@textfiles=grep -T,readdir(ACTIONDIR);
closedir(ACTIONDIR);
print "| Name | List format | Table format | Add |
|---|---|---|---|
| $_ | Display | "; print "Display | "; print ""; if ( -w "$actions_dir/$_" ) { print "Add"; } print " |
"; print "Total completed actions $completed
"; print "Total pending actions $pending
"; print "Total active actions $active
"; print "Total blocked actions $blocked
"; # use perl to pretty up the output. $manhours=$manhours*1.0; print "Total estimated man hours $manhours in $manhoursrecs records
"; print "Total estimated man hours for completed tasks ", &get_estimated_for_state(Completed),"
\n"; print "Total estimated man hours for pending tasks ", &get_estimated_for_state(Pending),"
\n"; print "Total estimated man hours for active tasks ", &get_estimated_for_state(Active),"
\n"; print "Total estimated man hours for blocked tasks ", &get_estimated_for_state(Blocked),"
\n"; &putfooter; exit; } if ($command eq "mark_complete") { print "received Mark_complete command cmdarg is $cmdarg $cmdarg1
";
&putfooter;
exit;
}
sub get_estimated_for_state {
my $state = shift(@_);
return `$tagbindir/tagextract -m Status -eq $state <$display_file | $tagbindir/tagshow -t Manhours-estimated` * 1.0;
}
if ($command eq "add") {
$basefile=basename($cmdarg,'\..*');
$sequence_file="$actions_dir/.$basefile.seq";
if (-w $sequence_file ) {
open SEQFILE, "+<$sequence_file" or die "Cant open $sequence_file: $!\n";
$next_id=";
print li(a{href=>"/cgi-bin/actions/display/$cmdarg"},"Action display for $cmdarg (list format)"),
li(a{href=>"/cgi-bin/actions/tdisplay/$cmdarg"},"Display in table format"),
li(a{href=>"/cgi-bin/actions/info/$cmdarg"},"Information about the actions");
if ( -w "$actions_dir/$cmdarg" ) {
print li(a{href=>"/cgi-bin/actions/add/$cmdarg"},"Add a new action to $cmdarg");
}
print li(a{href=>"/cgi-bin/actions/display/"},"Actions index");
print li(a{href=>"/cgi-bin/actions/about"},"About the actions script");
print "
";
}