Merge branch 'master' of /opt/git/clearscm
[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       "<img src=/maps/images/previous.gif border=0 alt=Previous align=middle>") : "";
72   my $next_button = ($next + $lines) < $total ?
73     a {-href => "list.cgi?type=$type;next=" . ($next + $lines)},
74       "<img src=/maps/images/next.gif border=0 alt=Next align=middle>" : "";
75   print $prev_button,
76     submit ({-name    => "action",
77              -value   => "Add New Entry",
78              -onClick => "return NoneChecked (document.list);"}),
79     submit ({-name    => "action",
80              -value   => "Delete Marked",
81              -onClick => "return CheckAtLeast1Checked (document.list) && AreYouSure ('Are you sure you want to delete these entries?');"}),
82     submit ({-name    => "action",
83              -value   => "Modify Marked",
84              -onClick => "return CheckAtLeast1Checked (document.list);"}),
85     submit ({-name    => "action",
86              -value   => "Reset Marks",
87              -onClick => "return ClearAll (document.list);"}),
88     $next_button;
89   print end_div;
90   print start_table {-align    => "center",
91          -id          => $table_name,
92          -border      => 0,
93          -cellspacing => 0,
94          -cellpadding => 4,
95          -width       => "100%"};
96   print Tr [
97     th {-class  => "tableleftend"},  "Seq",
98     th {-class  => "tableheader"},   "Mark",
99     th {-class  => "tableheader"},   "Username",
100     th {-class  => "tableheader"},   "@",
101     th {-class  => "tableheader"},   "Domain",
102     th {-class  => "tablerightend"}, "Comments"
103   ];
104
105   my @list = ReturnList $type, $next, $lines;
106   my %record;
107   my $i = 1;
108
109   foreach (@list) {
110     %record = %{$_};
111     $record{pattern}  = "&nbsp;" if !defined $record{pattern};
112     $record{domain}  = "&nbsp;" if !defined $record{domain};
113     $record{comment}  = "&nbsp;" if !defined $record{comment};
114
115     my $leftclass  = ($i eq $lines || $record{sequence} eq $total) ?
116       "tablebottomleft"  : "tableleftdata";
117     my $dataclass  = ($i eq $lines || $record{sequence} eq $total) ?
118       "tablebottomdata"  : "tabledata";
119     my $rightclass = ($i eq $lines || $record{sequence} eq $total) ?
120       "tablebottomright" : "tablerightdata";
121     $i++;
122
123     print Tr [
124       td {-class  => $leftclass,
125           -align  => "center"}, $record{sequence},
126       td {-class  => $dataclass,
127           -align  => "center"},
128     checkbox ({-name  => "action$record{sequence}",
129                -label => ""}),
130       td {-class  => $dataclass,
131           -align  => "right"}, $record{pattern},
132       td {-class  => $dataclass,
133           -align  => "center"}, "\@",
134       td {-class  => $dataclass,
135           -align  => "left"}, $record{domain},
136       td {-class  => $rightclass,
137           -align  => "left"}, $record{comment}
138     ];
139   } # foreach
140   print end_table;
141   print end_form;
142
143   print div ({-align  => "center"},
144     a ({-href => "/maps/bin/exportlist.cgi?type=$type"},
145       submit ({-name  => "export",
146                -value  => "Export List"})),
147     a ({-href => "/maps/bin/importlist.cgi?type=$type"},
148       submit ({-name  => "import",
149                -value  => "Import List"})));
150
151   return;
152 } # Body
153
154 # Main
155 my @scripts = ("ListActions.js");
156
157 $userid = Heading (
158   "getcookie",
159   "",
160   "Manage $Type List",
161   "Manage $Type List",
162   "",
163   $table_name,
164   @scripts
165 );
166
167 SetContext $userid;
168 NavigationBar $userid;
169
170 if (!defined $lines) {
171   my %options = GetUserOptions $userid;
172   $lines = $options{"Page"};
173 } # if
174
175 $total = MAPSDB::count "list", "userid = \"$userid\" and type = \"$type\"";;
176
177 $next = !defined $next ? 0 : $next;
178 $last = $next + $lines < $total ? $next + $lines : $total;
179
180 if (($next - $lines) > 0) {
181   $prev = $next - $lines;
182 } else {
183   $prev = $next == 0 ? -1 : 0;
184 } # if
185
186 Body $type;
187 Footing $table_name;
188
189 exit;