Minor cosmetic changes
[clearscm.git] / maps / bin / list.cgi
1 #!/usr/bin/perl
2 ################################################################################
3 #
4 # File:         $RCSfile: list.cgi,v $
5 # Revision:  $Revision: 1.1 $
6 # Description:  Manage lists
7 # Author:       Andrew@DeFaria.com
8 # Created:      Mon Jan 16 20:25:32 PST 2006
9 # Modified:     $Date: 2013/06/12 14:05:47 $
10 # Language:     perl
11 #
12 # (c) Copyright 2000-2006, Andrew@DeFaria.com, all rights reserved.
13 #
14 ################################################################################
15 use strict;
16 use warnings;
17
18 use FindBin;
19
20 local $0 = $FindBin::Script;
21
22 use lib $FindBin::Bin;
23
24 use MAPS;
25 use MAPSLog;
26 use MAPSUtil;
27 use MAPSWeb;
28 use CGI qw (:standard *table start_div end_div);
29 use CGI::Carp "fatalsToBrowser";
30
31 my $next    = param("next");
32 my $lines   = param("lines");
33 my $type    = param("type");
34 my $message = param("message");
35 my $Type    = ucfirst $type;
36 my $userid;
37 my $prev;
38 my $total;
39 my $last;
40 my $table_name = "list";
41
42 sub Body {
43   my $type = shift;
44
45   if (defined $message) {
46     print div {-align  => "center"},
47       font {-class  => "error"}, $message;
48   } # if
49
50   print start_form {
51     -method => "post",
52     -action => "processaction.cgi",
53     -name   => "list"
54   };
55
56   # Print some hidden fields to pass along
57   print
58     hidden (-name    => "type",
59             -default => $type),
60     hidden (-name    => "next",
61             -default => $next);
62
63   my $current = $next + 1;
64
65   print div {-align => "center"}, b (
66     "(" . $current . "-" . $last . " of " . $total . ")");
67   print start_div {-class  => "toolbar",
68                    -align  => "center"};
69   my $prev_button = $prev >= 0 ?
70     a ({-href      => "list.cgi?type=$type;next=$prev",
71         -accesskey => 'p',
72     }, "<img src=/maps/images/previous.gif border=0 alt=Previous align=middle>") : "";
73   my $next_button = ($next + $lines) < $total ?
74     a {-href      => "list.cgi?type=$type;next=" . ($next + $lines),
75        -accesskey => 'n',
76     }, "<img src=/maps/images/next.gif border=0 alt=Next align=middle>" : "";
77   print $prev_button,
78     submit ({-name    => "action",
79              -value   => "Add New Entry",
80              -onClick => "return NoneChecked (document.list);"}),
81     submit ({-name    => "action",
82              -value   => "Delete Marked",
83              -onClick => "return CheckAtLeast1Checked (document.list) && AreYouSure ('Are you sure you want to delete these entries?');"}),
84     submit ({-name    => "action",
85              -value   => "Modify Marked",
86              -onClick => "return CheckAtLeast1Checked (document.list);"}),
87     submit ({-name    => "action",
88              -value   => "Reset Marks",
89              -onClick => "return ClearAll (document.list);"}),
90     $next_button;
91   print end_div;
92   print start_table {-align    => "center",
93          -id          => $table_name,
94          -border      => 0,
95          -cellspacing => 0,
96          -cellpadding => 4,
97          -width       => "100%"};
98   print Tr [
99     th {-class  => "tableleftend"},  "Seq",
100     th {-class  => "tableheader"},   "Mark",
101     th {-class  => "tableheader"},   "Username",
102     th {-class  => "tableheader"},   "@",
103     th {-class  => "tableheader"},   "Domain",
104     th {-class  => "tablerightend"}, "Comments"
105   ];
106
107   my @list = ReturnList $type, $next, $lines;
108   my %record;
109   my $i = 1;
110
111   foreach (@list) {
112     %record = %{$_};
113     $record{pattern}  = "&nbsp;" if !defined $record{pattern};
114     $record{domain}  = "&nbsp;" if !defined $record{domain};
115     $record{comment}  = "&nbsp;" if !defined $record{comment};
116
117     my $leftclass  = ($i eq $lines || $record{sequence} eq $total) ?
118       "tablebottomleft"  : "tableleftdata";
119     my $dataclass  = ($i eq $lines || $record{sequence} eq $total) ?
120       "tablebottomdata"  : "tabledata";
121     my $rightclass = ($i eq $lines || $record{sequence} eq $total) ?
122       "tablebottomright" : "tablerightdata";
123     $i++;
124
125     print Tr [
126       td {-class  => $leftclass,
127           -align  => "center"}, $record{sequence},
128       td {-class  => $dataclass,
129           -align  => "center"},
130     checkbox ({-name  => "action$record{sequence}",
131                -label => ""}),
132       td {-class  => $dataclass,
133           -align  => "right"}, $record{pattern},
134       td {-class  => $dataclass,
135           -align  => "center"}, "\@",
136       td {-class  => $dataclass,
137           -align  => "left"}, $record{domain},
138       td {-class  => $rightclass,
139           -align  => "left"}, $record{comment}
140     ];
141   } # foreach
142   print end_table;
143   print end_form;
144
145   print div ({-align  => "center"},
146     a ({-href => "/maps/bin/exportlist.cgi?type=$type"},
147       submit ({-name  => "export",
148                -value  => "Export List"})),
149     a ({-href => "/maps/bin/importlist.cgi?type=$type"},
150       submit ({-name  => "import",
151                -value  => "Import List"})));
152
153   return;
154 } # Body
155
156 # Main
157 my @scripts = ("ListActions.js");
158
159 $userid = Heading (
160   "getcookie",
161   "",
162   "Manage $Type List",
163   "Manage $Type List",
164   "",
165   $table_name,
166   @scripts
167 );
168
169 SetContext $userid;
170 NavigationBar $userid;
171
172 if (!defined $lines) {
173   my %options = GetUserOptions $userid;
174   $lines = $options{"Page"};
175 } # if
176
177 $total = MAPSDB::count "list", "userid = \"$userid\" and type = \"$type\"";;
178
179 $next = !defined $next ? 0 : $next;
180 $last = $next + $lines < $total ? $next + $lines : $total;
181
182 if (($next - $lines) > 0) {
183   $prev = $next - $lines;
184 } else {
185   $prev = $next == 0 ? -1 : 0;
186 } # if
187
188 Body $type;
189 Footing $table_name;
190
191 exit;