#!/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 "

\nIndex of action files

\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 "

\nIndex of action files

\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 ""; print "\n"; foreach(@textfiles) { next if /^\./; print ""; print ""; print "\n"; } print "
NameList formatTable formatAdd
$_DisplayDisplay"; if ( -w "$actions_dir/$_" ) { print "Add"; } print "
"; print "
"; exit; } $display_file="$actions_dir/$cmdarg"; system("$tagbindir/tag2html <$display_file"); &putfooter; exit; } if ($command eq "tdisplay") { if ($cmdarg eq "") { print "No file supplied\n"; exit; } $display_file="$actions_dir/$cmdarg"; $not_done="cat $display_file"; $not_done="$tagbindir/tagextract -v -m Status -eq Completed < $display_file"; #system(" $tagbindir/tag2html -o border -t Id Title < $display_file"); system("$not_done | $tagbindir/tag2html -o border -t Id Title -l 'Complete'"); &putfooter; exit; } if ($command eq "sdisplay") { if ($cmdarg eq "") { print "No file supplied\n"; exit; } $display_file="$actions_dir/$cmdarg"; system("$tagbindir/tag2tab -t Priority Id Title <$display_file | sort | $tagbindir/tab2tag -t Priority Id Title | $tagbindir/tag2html -h -o border -t Id Priority Title"); &putfooter; exit; } if ($command eq "info") { if ($cmdarg eq "") { print "No file supplied\n"; exit; } $display_file="$actions_dir/$cmdarg"; $total_actions=`$tagbindir/tagcount -r $display_file`; $completed=`$tagbindir/tagcount -v Status Completed $display_file`; $pending=`$tagbindir/tagcount -v Status Pending $display_file`; $active=`$tagbindir/tagcount -v Status Active $display_file`; $blocked=`$tagbindir/tagcount -v Status Blocked $display_file`; $manhours=`$tagbindir/tagshow -t Manhours-estimated <$display_file`; $manhoursrecs=`$tagbindir/tagcount -f Manhours-estimated $display_file`; print "Total number of actions $total_actions

"; 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=; $id_default="$basefile.$next_id"; $next_id++; seek SEQFILE,0,0; print SEQFILE "$next_id\n"; close SEQFILE; } print start_html('Add a new action'),h1('Add a new action'), start_form, "Id "; if ($id_default ne "") { print textfield(-name=>'id',-default=>$id_default,-override=>1); print "Id default info found"; } else { print textfield('id'); print "Id default file $sequence_file not found"; } print br, "Title ", textfield(-name=>'title',-size=>60),br, "Description ", textarea(-name=>'description',-rows=>3,-columns=>60),br, "Expected-cost ", textfield(-name=>'expectedcost'),br, "Expected-time ", textfield(-name=>'expectedtime'),br, "Precursor ",textfield(-name=>'precursor'),br, "Priority ",textfield(-name=>'priority'),br, "Date ",textfield(-name=>'date'),br, "Assigned-to ",textfield(-name=>'assignedto'),br, "Status-notify ",textfield(-name=>'statusnotify'),br, "Active-after ",textfield(-name=>'activeafter'),br, "Contact-email ",textfield(-name=>'contactemail'),br, "Reason ",textarea(-name=>'reason',-rows=>3,-columns=>60),br, "Subtask-of ",textfield(-name=>'subtaskof'),br, "Manhours-estimated ",textfield(-name=>'manhoursestimated'),br, p, submit(-name=>'Add record'),reset,defaults, end_form,p; if (param()) { $display_file="$actions_dir/$cmdarg"; if (open (FILE,">>$display_file")) { print FILE "Id: ",param('id'),"\n"; print FILE "Title: ",param('title'),"\n"; print FILE "Description:: END_D\n",param('description'),"\nEND_D\n"; print FILE "Expected-cost: ",param('expectedcost'),"\n"; print FILE "Expected-time: ",param('expectedtime'),"\n"; print FILE "Precursor: ",param('precursor'),"\n"; print FILE "Priority: ",param('priority'),"\n"; print FILE "Date: ",param('date'),"\n"; print FILE "Assigned-to: ",param('assignedto'),"\n"; print FILE "Status-notify: ",param('statusnotify'),"\n"; print FILE "Active-after: ",param('activeafter'),"\n"; print FILE "Contact-email: ",param('contactemail'),"\n"; print FILE "Reason:: END_R\n",param('reason'),"\nEND_R\n"; print FILE "Subtask-of: ",param('subtaskof'),"\n"; print FILE "Manhours-estimated: ",param('manhoursestimated'),"\n"; print FILE "Added-by: ",remote_ident(),"@",remote_host(),"\n"; print FILE "End:\n\n"; close(FILE); } else { print "Error: could not write to file $display_file $!\n"; } } &putfooter; exit(0); } # if we get here then we did not recognise the command print "Command $command not recognised\n"; exit; # subroutines sub putfooter { # put out a standard footer for each page print hr,p; print "

"; }