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