+field "priority"
[www.jankratochvil.net.git] / project / list.cgi.pl
1 #! /usr/bin/perl
2
3 # $Id$
4 # List of projects Perl template.
5 # Copyright (C) 2003 Jan Kratochvil <project-www.jankratochvil.net@jankratochvil.net>
6
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; exactly version 2 of June 1991 is required
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
20
21 require 5.6.0;  # at least 'use warnings;' but we need some 5.6.0+ modules anyway
22 use vars qw($VERSION $CVS_ID);
23 $VERSION=do { my @r=(q$Revision$=~/\d+/g); sprintf "%d.".("%03d"x$#r),@r; };
24 $CVS_ID=q$Id$;
25 use strict;
26 use warnings;
27
28 use lib qw(/home/short/lib/perl5/site_perl/5.6.0/i386-linux /home/short/lib/perl5/site_perl/5.6.0 /home/short/lib/perl5/site_perl/i386-linux /home/short/lib/perl5/site_perl /home/short/lib/perl5/5.6.0/i386-linux /home/short/lib/perl5/5.6.0 /home/short/lib/perl5/i386-linux /home/short/lib/perl5);
29
30 use lib "../";
31 use My::Web;
32 require CGI;
33
34 use constant ENTRIES=>"CVS/Entries";
35 use constant ENTRIES_LOG=>"CVS/Entries.Log";
36
37
38 My::Web->init(
39                 "title"=>'Project List',
40                 );
41 My::Web->heading();
42
43 my $CGI=CGI->new();
44
45 print <<'HERE';
46 <h1>Project List of <a href="mailto:web-www.jankratochvil.net@jankratochvil.net">Jan Kratochvil</a></h1>
47
48 <p><form action="list.cgi.pl" method="GET">
49 <select name="description_opt" onchange="this.form.submit();">
50 HERE
51 print '<option value="0"'.(!$CGI->param("description_opt") ? ' selected="selected"' : '').'>only list</option>'."\n";
52 print '<option value="1"'.( $CGI->param("description_opt") ? ' selected="selected"' : '').'>incl. descriptions</option>'."\n";
53 print <<'HERE';
54 </select>
55 <input type="submit" value="Update" />
56 </form></p>
57 HERE
58
59 my %dirs;
60 for my $ENTRIES (ENTRIES,ENTRIES_LOG) {
61         local *E;
62         next if !open E,$ENTRIES;
63         while (<E>) {
64                 chomp;
65                 do { $dirs{$1}=1; next; } if m#^(?:A )?D/([^/]*)/#;
66                 next if m#^/([^/]*)/# ;
67                 next if /^D$/;
68                 warn "File $ENTRIES contains invalid line \"$_\": $!";
69                 }
70         close E;
71         }
72
73 my %item;
74 for my $dir (keys(%dirs)) {
75         require "$dir/ListItem.pm";
76         my $item=eval('\%My::Project::'.$dir.'::ListItem');
77         do { warn "Broken $dir/List.pm"; next; } if !defined %$item;
78         $item{$dir}=$item;
79         }
80
81 # $col{"name"}{"show"}=1
82 # $col{"name"}{"format"}=sub { "<".$_[0].">"; }
83 # $col{"name"}{""}="Project name";
84 # @col_order
85
86 my @row_order=qw(-priority);
87 my @col_order=qw(name summary license maintenance language);
88 my %col;
89
90 sub format_url ($) { return (!$_[0] ? "" : '<a href="'.$_[0].'">X</a>'); }
91
92 $col{"name"}{"format"}=sub {
93                 $_[0]=~s#<a\s[^>]*>([^<]*)</a>#$1#g;
94                 return "<a href=\"".$_[1]."/\">".$_[0]."</a>";
95                 };
96
97 $col{"license"}{"format"}=sub {
98                 my %known=(
99                                 "PD"=>"<a href=\"http://www.gnu.org/philosophy/categories.html#PublicDomainSoftware\">PD</a>",
100                                 "GPL"=>"<a href=\"http://www.gnu.org/licenses/gpl.html\">GPL</a>",
101                                 "LGPL"=>"<a href=\"http://www.gnu.org/licenses/lgpl.html\">LGPL</a>",
102                                 );
103                 return $known{$_[0]} if $known{$_[0]};
104                 return $_[0];
105                 };
106
107 $col{"online-demo"}{"format"}=\&format_url;
108 $col{"download"}{"format"}=\&format_url;
109 $col{"name"}{""}="Project Name";
110 $col{"summary"}{""}="Abstract";
111 $col{"license"}{""}="Copying";
112 $col{"maintenance"}{""}="State";
113 $col{"language"}{""}="Language";
114
115 # Fill in cols not contained in @col_order
116 if (0) {
117         my %col_order=map(($_=>1),@col_order);
118         push @col_order,map({ ($col_order{$_} ? () : $_); } keys(%{{ map(($_=>1),map((keys(%{$item{$_}})),keys(%item)))}}));
119         }
120
121 print '<table border="1">'."\n";
122         print '<tr>';
123                 for my $col (@col_order) {
124                         next if defined $col{$col}{"show"} && !$col{$col}{"show"};
125                         print '<th>'.($col{$col}{""} || "[$col]").'</th>';
126                         }
127         print '</tr>'."\n";
128         my @rows_ordered=sort {
129                         for my $order_by (@row_order,"name") {
130                                 my $order_by=$order_by;
131                                 my $minus=($order_by=~s/^(-)//)[0];
132                                 my $r=($item{$a}{$order_by} cmp $item{$b}{$order_by});
133                                 $r=-$r if $minus;
134                                 return $r if $r;
135                                 }
136                         return 0;
137                         } keys(%item);
138         for my $row (@rows_ordered) {
139                 print '<tr>';
140                 for my $col (@col_order) {
141                         next if defined $col{$col}{"show"} && !$col{$col}{"show"};
142                         print '<td>';
143                         if (!$col{$col}{"format"}) {
144                                 print(($item{$row}{$col} || ""));
145                                 }
146                         else {
147                                 print(&{$col{$col}{"format"}}($item{$row}{$col},$row));
148                                 }
149                         print '</td>';
150                         }
151                 print '</tr>'."\n";
152                 if ($CGI->param("description_opt")) {
153                         print '<tr><td style="border: none;"></td>';
154                         print '<td colspan="'.(scalar(@col_order)-1).'"><blockquote>'.$item{$row}{"description"}.'</blockquote></td>';
155                         print '</tr>'."\n";
156                         print '<tr><td style="border: none;" colspan="'.scalar(@col_order).'">&nbsp;</td></tr>'."\n";
157                         }
158                 }
159 print '</table>'."\n";
160
161 My::Web->footer();