| 4 |
- |
1 |
#!/usr/bin/perl
|
|
|
2 |
|
|
|
3 |
#if ($ENV{SHELL}) { die "This script shouldn't be executed from the command line!\n"; }
|
|
|
4 |
|
|
|
5 |
use CGI qw/:standard escape/;
|
|
|
6 |
use scanFunctions;
|
|
|
7 |
|
|
|
8 |
|
|
|
9 |
my $pageTitle = "CC Roasters";
|
|
|
10 |
my $prefscookie = "CCRoastersPrefs";
|
|
|
11 |
our $DBTABLE = 'roasters';
|
|
|
12 |
my %COLUMNS = (
|
|
|
13 |
roaster => [qw(Roaster 5 text static)],
|
|
|
14 |
url => [qw(URL 10 text static)],
|
|
|
15 |
location => [qw(Location 15 text static)],
|
|
|
16 |
notes => [qw(Notes 20 text)]
|
|
|
17 |
);
|
|
|
18 |
our @defaultFields = (qw(roaster url location));
|
|
|
19 |
my $stylesheet = "style.css";
|
|
|
20 |
|
|
|
21 |
# If we need to modify line item values, create a subroutine named "modify_$columnname"
|
|
|
22 |
# It will recieve a hashref to the object lineitem
|
|
|
23 |
|
|
|
24 |
sub modify_roaster {
|
|
|
25 |
# Turn it into a link to the manage_roaster.pl page
|
|
|
26 |
my $lineItem = shift;
|
|
|
27 |
my $rster = escape ($lineItem->{'roaster'});
|
|
|
28 |
return a ({-href=>"/manage_roaster.pl?roaster=$rster"}, $lineItem->{'roaster'});
|
|
|
29 |
}
|
|
|
30 |
|
|
|
31 |
sub modify_url {
|
|
|
32 |
# Make the URL an actual link
|
|
|
33 |
my $lineItem = shift;
|
|
|
34 |
return a ({-href=>$lineItem->{'url'}, -target=>"_blank"}, $lineItem->{'url'});
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
|
|
|
38 |
|
|
|
39 |
|
|
|
40 |
# Ideally, nothing below this comment needs to change
|
|
|
41 |
#-------------------------------------------------------------------------------
|
|
|
42 |
|
|
|
43 |
our %NAME = map { $_ => $COLUMNS{$_}->[0] } keys %COLUMNS;
|
|
|
44 |
our %colOrderHash = map { $_ => $COLUMNS{$_}->[1] } keys %COLUMNS;
|
|
|
45 |
our %colFilterTypeHash = map { $_ => $COLUMNS{$_}->[2] } keys %COLUMNS;
|
|
|
46 |
our @staticFields = grep { $COLUMNS{$_}->[3] eq 'static' } keys %COLUMNS;
|
|
|
47 |
|
|
|
48 |
our @allFields = sort byfield keys %NAME;
|
|
|
49 |
our @displayFields = ();
|
|
|
50 |
our @hideFields = ();
|
|
|
51 |
my $QUERY_STRING;
|
|
|
52 |
|
|
|
53 |
|
|
|
54 |
our %FORM;
|
|
|
55 |
foreach (param())
|
|
|
56 |
{
|
|
|
57 |
$FORM{$_} = param($_); # Retrieve all of the FORM data submitted
|
|
|
58 |
|
|
|
59 |
if ((/^filter/) and ($FORM{$_} ne '')) # Build a set of filters to apply
|
|
|
60 |
{
|
|
|
61 |
my ($filter,$field) = split /-/, $_;
|
|
|
62 |
|
|
|
63 |
$FILTER->{$field} = $FORM{$_};
|
|
|
64 |
}
|
|
|
65 |
elsif ($FORM{$_} eq "true") # Compile list of fields to display
|
|
|
66 |
{ push @displayFields, $_; }
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
|
|
|
70 |
if (exists $FORM{autoload}) # If the FORM was submitted (i.e. the page is being redisplayed),
|
|
|
71 |
{ # build the data for the cookie that remembers the page setup
|
|
|
72 |
my $disFields = join ":", @displayFields;
|
|
|
73 |
my $fils = join ":", map { "$_=$FILTER->{$_}" } keys %{$FILTER};
|
|
|
74 |
|
|
|
75 |
$QUERY_STRING = $disFields.'&'.$fils.'&'.$FORM{autoload};
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
|
|
|
79 |
if (!(exists $FORM{autoload})) # No FORM was submitted...
|
|
|
80 |
{
|
|
|
81 |
if (my $prefs = cookie($prefscookie)) # Check for cookies from previous visits.
|
|
|
82 |
{
|
|
|
83 |
my ($disF, $filts, $al) = split /&/,$prefs;
|
|
|
84 |
@displayFields = split /:/,$disF;
|
|
|
85 |
|
|
|
86 |
foreach $pair (split /:/, $filts)
|
|
|
87 |
{
|
|
|
88 |
my ($key, $value) = split /=/, $pair;
|
|
|
89 |
$FORM{"filter-$key"} = $value;
|
|
|
90 |
$FILTER->{$key} = $value;
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
$FORM{autoload} = $al;
|
|
|
94 |
$QUERY_STRING = $prefs;
|
|
|
95 |
}
|
|
|
96 |
else # Otherwise suppply a default list of columns.
|
|
|
97 |
{ @displayFields = @defaultFields; }
|
|
|
98 |
}
|
|
|
99 |
|
|
|
100 |
# let's just make sure the columns are in the right order
|
|
|
101 |
@displayFields = sort byfield @displayFields;
|
|
|
102 |
|
|
|
103 |
# If the field isn't in the displayFields list, then add it to the hideFields list
|
|
|
104 |
@hideFields = grep { notInArray ($_, \@displayFields) } @allFields;
|
|
|
105 |
|
|
|
106 |
# Process any filters provided in the form to pass to the database
|
|
|
107 |
my @whereClause = map { filter ($_, $FILTER->{$_}) } grep { defined $FILTER->{$_} } @displayFields;
|
|
|
108 |
|
|
|
109 |
# Given the fields to display and the where conditions,
|
|
|
110 |
# "getData" will return a reference to an array of
|
|
|
111 |
# hash references of the results.
|
|
|
112 |
my @ProductList = @{ getData (\@displayFields, \@whereClause, $DBTABLE) };
|
|
|
113 |
my $x = scalar @ProductList; # How many results were returned?
|
|
|
114 |
|
|
|
115 |
# Set some cookie stuff...
|
|
|
116 |
my $path = `dirname $ENV{REQUEST_URI}`; chomp $path; $path .= '/' unless $path eq "/";
|
|
|
117 |
my $queryCookie = cookie(-NAME=>$prefscookie,
|
|
|
118 |
-VALUE=>"$QUERY_STRING",
|
|
|
119 |
-PATH=>"$path",
|
|
|
120 |
-EXPIRES=>'+365d');
|
|
|
121 |
|
|
|
122 |
print header (-cookie=> [$queryCookie] );
|
|
|
123 |
|
|
|
124 |
# print "<!-- FORM \n\n"; # Debug code to dump the FORM to a html comment
|
|
|
125 |
# print "I'm catching updates!!!\n\n";
|
|
|
126 |
# foreach $key (sort (keys %FORM)) # Must be done after the header is written!
|
|
|
127 |
# { print "\t$key: $FORM{$key}\n"; }
|
|
|
128 |
# print "--> \n\n";
|
|
|
129 |
#
|
|
|
130 |
#
|
|
|
131 |
# print "<!-- ENV \n\n"; # Debug code to dump the ENV to a html comment
|
|
|
132 |
# foreach $key (sort (keys %ENV)) # Must be done after the header is written!
|
|
|
133 |
# { print "\t$key: $ENV{$key}\n"; }
|
|
|
134 |
# print "--> \n\n";
|
|
|
135 |
#
|
|
|
136 |
# print "\n\n\n\n<!-- $QUERY_STRING --> \n\n\n\n";
|
|
|
137 |
|
|
|
138 |
|
|
|
139 |
#------------------
|
|
|
140 |
|
|
|
141 |
our ($onClick, $onChange);
|
|
|
142 |
if ($FORM{autoload}) # Toggle the autoload fields within the table elements
|
|
|
143 |
{ $onClick = "onClick='submit();'";
|
|
|
144 |
$onChange = "onChange='submit();'"; }
|
|
|
145 |
else
|
|
|
146 |
{ $onClick = "";
|
|
|
147 |
$onChange = ""; }
|
|
|
148 |
|
|
|
149 |
print start_html (-title => $pageTitle, -style => {'src' => $stylesheet} );
|
|
|
150 |
print start_form (-action => url (), -method => "POST", -name => "Req");
|
|
|
151 |
$pageTitle = h1 ($pageTitle);
|
|
|
152 |
|
|
|
153 |
print<<header;
|
|
|
154 |
<div class="accent pageheader">$pageTitle</div>
|
|
|
155 |
<br>
|
|
|
156 |
|
|
|
157 |
<div class=sp0>
|
|
|
158 |
<div class=spLeft>
|
|
|
159 |
<div class=rTable>
|
|
|
160 |
header
|
|
|
161 |
|
|
|
162 |
# Print the Hidden fields' check boxes
|
|
|
163 |
|
|
|
164 |
my $tc = 1;
|
|
|
165 |
foreach $field (sort { $NAME{$a} cmp $NAME{$b}; } @hideFields) {
|
|
|
166 |
if ($tc == 1) { print "<div class=rTableRow>\n"; }
|
|
|
167 |
print "<div class=rTableCell nowrap><b><INPUT type=checkbox name=$field value=true $onClick class=accent>$NAME{$field}</div>\n";
|
|
|
168 |
if ($tc == 4) { print "\t\t\t\t\t\t</div>\n"; $tc = 1; }
|
|
|
169 |
$tc++;
|
|
|
170 |
}
|
|
|
171 |
print "</div>\n" unless $tc == 1;
|
|
|
172 |
|
|
|
173 |
if ($FORM{autoload}) {
|
|
|
174 |
$trueChecked = "checked";
|
|
|
175 |
$falseChecked = "";
|
|
|
176 |
} else {
|
|
|
177 |
$trueChecked = "";
|
|
|
178 |
$falseChecked = "checked";
|
|
|
179 |
}
|
|
|
180 |
|
|
|
181 |
print<<header3;
|
|
|
182 |
</div>
|
|
|
183 |
<div align=center>
|
|
|
184 |
<b>Autoload: <INPUT type=radio name=autoload value=1 onClick='Req.submit();' $trueChecked class=accent>On <INPUT type=radio name=autoload value=0 onClick='Req.submit();' $falseChecked class=accent>Off
|
|
|
185 |
<br><br>
|
|
|
186 |
</div>
|
|
|
187 |
</div>
|
|
|
188 |
|
|
|
189 |
<div class=spRight>
|
|
|
190 |
<B><input type=button value="Refresh Display" onClick="window.document.Req.submit(); return false;"><br><br>
|
|
|
191 |
Display <A HREF='' onClick="window.document.Req.method = 'GET'; window.document.Req.submit(); return false;">Full URL</a> : <a href=/>[Go HOME]</a>
|
|
|
192 |
<br><br>
|
|
|
193 |
</div>
|
|
|
194 |
</div>
|
|
|
195 |
|
|
|
196 |
<div class=rTable width=100\%>
|
|
|
197 |
<div class=rTableRow>
|
|
|
198 |
header3
|
|
|
199 |
|
|
|
200 |
# Print the Column headings
|
|
|
201 |
foreach $f (@displayFields) {
|
|
|
202 |
if (inArray ($f, \@staticFields)) {
|
|
|
203 |
print "<div class=rTableHead><INPUT type=hidden name=$f value=true>$NAME{$f}</div>\n";
|
|
|
204 |
} else {
|
|
|
205 |
print "<div class=rTableHead><INPUT type=checkbox name=$f value=true checked $onClick class=accent>$NAME{$f}</div>\n";
|
|
|
206 |
}
|
|
|
207 |
}
|
|
|
208 |
|
|
|
209 |
print "</div><div class=rTableRow>\n";
|
|
|
210 |
|
|
|
211 |
# and now the filter boxes
|
|
|
212 |
foreach $f (@displayFields) {
|
|
|
213 |
print "\t\t\t\t\t<div class='rTableCell filters'>";
|
|
|
214 |
print filter ($f);
|
|
|
215 |
print "</div>\n";
|
|
|
216 |
}
|
|
|
217 |
|
|
|
218 |
print "</div>\n";
|
|
|
219 |
print end_form (), "\n";
|
|
|
220 |
|
|
|
221 |
my $cw = scalar @displayFields;
|
|
|
222 |
|
|
|
223 |
print<<header2;
|
|
|
224 |
<div class=rTableRow>
|
|
|
225 |
<div class=rTableCell></div>
|
|
|
226 |
</div class=rTableRow>
|
|
|
227 |
header2
|
|
|
228 |
|
|
|
229 |
|
|
|
230 |
foreach $t (@ProductList) # Unt now we print the things!
|
|
|
231 |
{
|
|
|
232 |
print "\t\t\t\t<div class='rTableRow shaded'>\n";
|
|
|
233 |
foreach $f (@displayFields)
|
|
|
234 |
{
|
|
|
235 |
# Look to see if there's a function named modify_<fieldname>() defined for this field
|
|
|
236 |
if (exists &{"modify_".$f}) {
|
|
|
237 |
$t->{$f} = &{"modify_".$f} ($t);
|
|
|
238 |
}
|
|
|
239 |
|
|
|
240 |
print "<div class=rTableCell valign=top>".$t->{$f}." </div>\n";
|
|
|
241 |
}
|
|
|
242 |
print "</div>\n";
|
|
|
243 |
}
|
|
|
244 |
|
|
|
245 |
print<<tail;
|
|
|
246 |
</div>
|
|
|
247 |
|
|
|
248 |
|
|
|
249 |
|
|
|
250 |
<br><br>
|
|
|
251 |
<FONT size=2><B>$x Record(s) Displayed</font>
|
|
|
252 |
<BR><BR>
|
|
|
253 |
<FONT size=1><B>This page was displayed on $now<BR>
|
|
|
254 |
Please direct questions, problems, and concerns to noone\@gmail.com
|
|
|
255 |
|
|
|
256 |
<SCRIPT language="JavaScript">
|
|
|
257 |
<!--
|
|
|
258 |
|
|
|
259 |
var ticket_window, severity_window, user_window;
|
|
|
260 |
|
|
|
261 |
function NewWindow () {
|
|
|
262 |
if ((ticket_window == null) || (ticket_window.closed == true))
|
|
|
263 |
ticket_window = open(\"\",\"Details\",\"width=650,height=650,menubar,scrollbars,resizable\");
|
|
|
264 |
ticket_window.focus();
|
|
|
265 |
return true;
|
|
|
266 |
}
|
|
|
267 |
|
|
|
268 |
function SevWindow () {
|
|
|
269 |
if ((severity_window == null) || (severity_window.closed == true))
|
|
|
270 |
severity_window = open(\"\",\"SevDetails\",\"width=500,height=300,menubar\");
|
|
|
271 |
severity_window.focus();
|
|
|
272 |
return true;
|
|
|
273 |
}
|
|
|
274 |
|
|
|
275 |
function UserWindow () {
|
|
|
276 |
if ((user_window == null) || (user_window.closed == true))
|
|
|
277 |
user_window = open(\"\",\"UserDetails\",\"width=310,height=115,menubar\");
|
|
|
278 |
user_window.focus();
|
|
|
279 |
return true;
|
|
|
280 |
}
|
|
|
281 |
|
|
|
282 |
//-->
|
|
|
283 |
</SCRIPT>
|
|
|
284 |
|
|
|
285 |
tail
|
|
|
286 |
|
|
|
287 |
print end_html;
|