Subversion Repositories CoffeeCatalog

Rev

Rev 7 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7 Rev 9
Line 10... Line 10...
10
 
10
 
11
my $pageTitle = "CC Roasters";
11
my $pageTitle = "CC Roasters";
12
my $prefscookie = "CCRoastersPrefs";
12
my $prefscookie = "CCRoastersPrefs";
13
our $DBTABLE = 'roasters';
13
our $DBTABLE = 'roasters';
14
my %COLUMNS = (
14
my %COLUMNS = (
15
	roaster   =>  [qw(Roaster     5    text     static)],
15
	roaster   =>  [qw(Roaster           5    text     static)],
16
	url       =>  [qw(URL        10    text     default)],
16
	url       =>  [qw(URL              10    text     default)],
17
	location  =>  [qw(Location   15    text     default)],
17
	location  =>  [qw(Location         15    text     default)],
-
 
18
	note      =>  [qw(Notes            20    text)],
18
	note      =>  [qw(Notes      20    text)]
19
	date_added => [qw(Date Added  25    date)]
19
);
20
);
20
my $stylesheet = "style.css";
21
my $stylesheet = "style.css";
-
 
22
my $homeURL = '/';
Line 21... Line 23...
21
my $homeURL = '/';
23
my @pagelimitoptions = (5, 10, 25, "All");
22
 
24
 
Line 23... Line 25...
23
# If we need to modify line item values, create a subroutine named "modify_$columnname"
25
# If we need to modify line item values, create a subroutine named "modify_$columnname"
Line 34... Line 36...
34
  # Make the URL an actual link
36
  # Make the URL an actual link
35
  my $lineItem = shift; 
37
  my $lineItem = shift; 
36
  return $h->a ({ href=>$lineItem->{'url'}, -target=>"_blank" }, $lineItem->{'url'});
38
  return $h->a ({ href=>$lineItem->{'url'}, -target=>"_blank" }, $lineItem->{'url'});
37
}
39
}
Line -... Line 40...
-
 
40
 
-
 
41
my $addNewButton = $h->div ({ style=>"float:right;" }, $h->input ({ type=>"button", value=>"Add New", style=>"margin:0;", onClick=>"window.location.href='manage_roaster.pl'" }));
Line 38... Line 42...
38
 
42
 
39
 
43
 
Line 40... Line 44...
40
 
44
 
41
 
45
 
42
# Ideally, nothing below this comment needs to change
46
# Ideally, nothing below this comment needs to change
43
#-------------------------------------------------------------------------------
47
#-------------------------------------------------------------------------------
44
 
48
 
45
 
49
 
Line 46... Line 50...
46
our %NAME              = map  { $_ => $COLUMNS{$_}->[0] } keys %COLUMNS;
50
our %NAME              = map  { $_ => $COLUMNS{$_}->[0] } keys %COLUMNS;
47
our %colOrderHash      = map  { $_ => $COLUMNS{$_}->[1] } keys %COLUMNS;
51
our %colOrderHash      = map  { $_ => $COLUMNS{$_}->[1] } keys %COLUMNS;
48
our %colFilterTypeHash = map  { $_ => $COLUMNS{$_}->[2] } keys %COLUMNS;
52
our %colFilterTypeHash = map  { $_ => $COLUMNS{$_}->[2] } keys %COLUMNS;
49
our @staticFields      = grep { $COLUMNS{$_}->[3] eq 'static' } keys %COLUMNS;
53
our @staticFields      = sort byfield grep { $COLUMNS{$_}->[3] eq 'static' } keys %COLUMNS;
Line -... Line 54...
-
 
54
our @defaultFields     = grep { defined $COLUMNS{$_}->[3] } keys %COLUMNS;
-
 
55
#our @defaultFields     = grep { $COLUMNS{$_}->[3] eq 'default' or inArray ($_, \@staticFields) } keys %COLUMNS;
Line 50... Line 56...
50
our @defaultFields     = grep { defined $COLUMNS{$_}->[3] } keys %COLUMNS;
56
 
51
#our @defaultFields     = grep { $COLUMNS{$_}->[3] eq 'default' or inArray ($_, \@staticFields) } keys %COLUMNS;
57
our @allFields = sort byfield keys %NAME;
52
 
58
our @displayFields = ();
Line 71... Line 77...
71
if (exists $FORM{autoload})	{			# If the FORM was submitted (i.e. the page is being redisplayed),
77
if (exists $FORM{autoload})	{			# If the FORM was submitted (i.e. the page is being redisplayed),
72
							                    #  	build the data for the cookie that remembers the page setup
78
							                    #  	build the data for the cookie that remembers the page setup
73
	my $disFields = join ":", @displayFields;
79
	my $disFields = join ":", @displayFields;
74
	my $fils = join ":", map { "$_=$FILTER->{$_}" } keys %{$FILTER};
80
	my $fils = join ":", map { "$_=$FILTER->{$_}" } keys %{$FILTER};
Line 75... Line 81...
75
		
81
		
76
	$QUERY_STRING = $disFields.'&'.$fils.'&'.$FORM{autoload};
82
	$QUERY_STRING = $disFields.'&'.$fils.'&'.$FORM{sortby}.'&'.$FORM{autoload};
Line 77... Line 83...
77
}
83
}
78
 
84
 
79
 
85
 
80
if (!(exists $FORM{autoload}))	{			# No FORM was submitted...
86
if (!(exists $FORM{autoload}))	{			# No FORM was submitted...
Line 81... Line 87...
81
	if (my $prefs = cookie($prefscookie))	{ # Check for cookies from previous visits.
87
	if (my $prefs = cookie ($prefscookie) and !defined param ("ignoreCookie"))	{ # Check for cookies from previous visits.
82
		my ($disF, $filts, $al) = split /&/,$prefs;
88
		my ($disF, $filts, $sb, $al) = split /&/,$prefs;
83
		@displayFields = split /:/,$disF;
89
		@displayFields = split /:/,$disF;
84
		
90
		
85
		foreach $pair (split /:/, $filts)	{
91
		foreach $pair (split /:/, $filts)	{
Line -... Line 92...
-
 
92
			my ($key, $value) = split /=/, $pair;
86
			my ($key, $value) = split /=/, $pair;
93
			$FORM{"filter-$key"} = $value;
87
			$FORM{"filter-$key"} = $value;
94
			$FILTER->{$key} = $value;
88
			$FILTER->{$key} = $value;
95
		}
89
		}
96
		
Line 103... Line 110...
103
my @whereClause = map { filter ($_, $FILTER->{$_}) } grep { defined $FILTER->{$_} } @displayFields;
110
my @whereClause = map { filter ($_, $FILTER->{$_}) } grep { defined $FILTER->{$_} } @displayFields;
Line 104... Line 111...
104
 
111
 
105
							#  Given the fields to display and the where conditions,
112
							#  Given the fields to display and the where conditions,
106
							#	  "getData" will return a reference to an array of
113
							#	  "getData" will return a reference to an array of
-
 
114
							#	  hash references of the results.
-
 
115
my ($data, $datacount) = getData (\@displayFields, \@whereClause, $DBTABLE, $FORM{sortby}, $curpage, $pagelimit);
-
 
116
my @ProductList = @{ $data };
107
							#	  hash references of the results.
117
 
108
my @ProductList = @{ getData (\@displayFields, \@whereClause, $DBTABLE) };
118
#my @ProductList = @{ getData (\@displayFields, \@whereClause, $DBTABLE, $FORM{sortby}, $curpage, $pagelimit) };
Line 109... Line 119...
109
my $x = scalar @ProductList; # How many results were returned?
119
my $x = scalar @ProductList; # How many results were returned?
110
 
120
 
111
# Set some cookie stuff...
121
# Set some cookie stuff...
Line 134... Line 144...
134
 
144
 
Line 135... Line 145...
135
#------------------
145
#------------------
136
 
146
 
137
# Toggle the autoload fields within the table elements 
147
# Toggle the autoload fields within the table elements 
138
our ($onClick, $onChange);   # (also used in scanFunctions)
148
our ($onClick, $onChange);   # (also used in scanFunctions)
139
my ($radiobutton, $refreshbutton);
149
my ($radiobutton, $refreshbutton, $sortby);
140
if ($FORM{autoload}) {					  
150
if ($FORM{autoload}) {					  
141
	$onClick = "onClick='submit();'";
151
	$onClick = "onClick='submit();'";
142
	$onChange = "onChange='submit();'";
152
	$onChange = "onChange='submit();'";
143
  $radiobutton = $h->div ({ class=>'autoload' },
153
  $radiobutton = $h->div ({ class=>'autoload' },
144
    ["Autoload Changes: ",
154
    ["Autoload Changes: ",
145
    $h->input ({ type=>radio, name=>'autoload', class=>'accent', value=>1, onClick=>'submit();', checked=>[] }), "On ", 
155
    $h->input ({ type=>radio, name=>'autoload', class=>'accent', value=>1, onClick=>'submit();', checked=>[] }), "On ", 
-
 
156
    $h->input ({ type=>radio, name=>'autoload', class=>'accent', value=>0, onClick=>'submit();' }), "Off ",
146
    $h->input ({ type=>radio, name=>'autoload', class=>'accent', value=>0, onClick=>'submit();' }), "Off ",
157
    ]);
147
    ]);
158
  $sortby = $h->select ({name=>sortby, onChange=>'submit();' }, [ map { $FORM{sortby} eq $_ ? $h->option ({ value=>$_, selected=>[] }, $NAME{$_}) : $h->option ({ value=>$_ }, $NAME{$_}) } @displayFields ]);
148
} else {
159
} else {
149
  $onClick = "";
160
  $onClick = "";
150
	$onChange = "";
161
	$onChange = "";
151
  $radiobutton = $h->div ({ class=>'autoload' }, 
162
  $radiobutton = $h->div ({ class=>'autoload' }, 
152
    ["Autoload Changes: ",
163
    ["Autoload Changes: ",
153
    $h->input ({ type=>radio, name=>'autoload', class=>'accent', value=>1, onClick=>'submit();' }), "On ", 
164
    $h->input ({ type=>radio, name=>'autoload', class=>'accent', value=>1, onClick=>'submit();' }), "On ", 
154
    $h->input ({ type=>radio, name=>'autoload', class=>'accent', value=>0, onClick=>'submit();', checked=>[] }), "Off ",
165
    $h->input ({ type=>radio, name=>'autoload', class=>'accent', value=>0, onClick=>'submit();', checked=>[] }), "Off ",
-
 
166
    ]);
155
    ]);
167
  $refreshbutton = $h->input ({ type=>"button", value=>"Apply Changes", onClick=>"submit(); return false;" });
Line -... Line 168...
-
 
168
  $sortby = $h->select ({name=>sortby }, [ map { $FORM{sortby} eq $_ ? $h->option ({ value=>$_, selected=>[] }, $NAME{$_}) : $h->option ({ value=>$_ }, $NAME{$_}) } @displayFields ]);
-
 
169
}
Line 156... Line 170...
156
  $refreshbutton = $h->input ({ type=>"button", value=>"Apply Changes", onClick=>"submit(); return false;" });
170
 
Line 157... Line 171...
157
}
171
 
Line 180... Line 194...
180
my $c = 1;
194
my $c = 1;
181
my @hiddencheckboxes;
195
my @hiddencheckboxes;
182
my @hiddenrows;
196
my @hiddenrows;
183
foreach $field (sort { $NAME{$a} cmp $NAME{$b}; } @hideFields) {
197
foreach $field (sort { $NAME{$a} cmp $NAME{$b}; } @hideFields) {
184
  if ($FORM{autoload}) {
198
  if ($FORM{autoload}) {
185
    push @hiddencheckboxes, $h->div ({ class=>'rTableCell quarters', nowrap=>[], onClick=>"Req.$field.click();" }, [ $h->input ({ type=>'checkbox', class=>'accent', name=>$field, value=>'true', onClick=>"event.stopPropagation(); submit();" }), $NAME{$field} ]);
199
    push @hiddencheckboxes, $h->div ({ class=>'rTableCell quarters nowrap', onClick=>"Req.$field.click();" }, [ $h->input ({ type=>'checkbox', class=>'accent', name=>$field, value=>'true', onClick=>"event.stopPropagation(); submit();" }), $NAME{$field} ]);
186
  } else {
200
  } else {
187
    push @hiddencheckboxes, $h->div ({ class=>'rTableCell quarters', nowrap=>[], onClick=>"Req.$field.checked=!Req.$field.checked;" }, [ $h->input ({ type=>'checkbox', class=>'accent', name=>$field, value=>'true', onClick=>"event.stopPropagation();" }), $NAME{$field} ]);
201
    push @hiddencheckboxes, $h->div ({ class=>'rTableCell quarters nowrap', onClick=>"Req.$field.checked=!Req.$field.checked;" }, [ $h->input ({ type=>'checkbox', class=>'accent', name=>$field, value=>'true', onClick=>"event.stopPropagation();" }), $NAME{$field} ]);
188
  }
202
  }
189
  if (! $c % 4) {
203
  if ($c++ % 4 == 0) {
190
    push @hiddenrows, $h->div ({ class=>'rTableRow' }, [ @hiddencheckboxes ]);
204
    push @hiddenrows, $h->div ({ class=>'rTableRow' }, [ @hiddencheckboxes ]);
191
    @hiddencheckboxes = [];
205
    @hiddencheckboxes = [];
192
    $c++;
-
 
193
  }
206
  }
194
}
207
}
195
push @hiddenrows, $h->div ({ class=>'rTableRow' }, [ @hiddencheckboxes ]) unless ! $c % 4;
208
push @hiddenrows, $h->div ({ class=>'rTableRow' }, [ @hiddencheckboxes ]) unless --$c % 4 == 0;
Line 196... Line 209...
196
 
209
 
197
 
210
 
198
if (scalar @hideFields) {
211
if (scalar @hideFields) {
Line 212... Line 225...
212
print $h->open ('div', { class=>'rTable' });
225
print $h->open ('div', { class=>'rTable' });
Line 213... Line 226...
213
 
226
 
214
my @tmptitlerow;
227
my @tmptitlerow;
215
foreach $f (@displayFields)	{  # Print the Column headings
228
foreach $f (@displayFields)	{  # Print the Column headings
216
  if (inArray ($f, \@staticFields)) {
229
  if (inArray ($f, \@staticFields)) {
-
 
230
    push @tmptitlerow, $h->div ({ class=>'rTableHead' }, [ $h->input ({ type=>"hidden", name=>$f, value=>"true" }), $NAME{$f}, $addNewButton ]);
217
    push @tmptitlerow, $h->div ({ class=>'rTableHead' }, [ $h->input ({ type=>"hidden", name=>$f, value=>"true" }), $NAME{$f} ]);
231
    $addNewButton = "";
218
  } else {
232
  } else {
219
    if ($FORM{autoload}) {
233
    if ($FORM{autoload}) {
220
      push @tmptitlerow, $h->div ({ class=>'rTableHead', onClick=>"Req.$f.click();" }, [ $h->input ({ type=>"checkbox", class=>"accent", name=>$f, value=>"true", checked=>[], onClick=>'event.stopPropagation(); submit();' }), $NAME{$f} ]);
234
      push @tmptitlerow, $h->div ({ class=>'rTableHead', onClick=>"Req.$f.click();" }, [ $h->input ({ type=>"checkbox", class=>"accent", name=>$f, value=>"true", checked=>[], onClick=>'event.stopPropagation(); submit();' }), $NAME{$f} ]);
221
    } else {
235
    } else {
Line 247... Line 261...
247
 
261
 
Line 248... Line 262...
248
print $h->close ('div');
262
print $h->close ('div');
Line -... Line 263...
-
 
263
 
-
 
264
# close things out................................................
-
 
265
 
-
 
266
my $pages = $pagelimit eq "All" ? 1 : int( $datacount / $pagelimit + 0.99 );
249
 
267
if ($curpage > $pages) { $curpage = $pages; }
250
# close things out................................................
268
 
251
 
269
 
252
print $h->br; # print $h->br;
270
print $h->br; # print $h->br;
253
print $h->div ({ class=>"sp0" }, [
271
print $h->div ({ class=>"sp0" }, [
254
    $h->div ({ class=>"spLeft" }, [
272
    $h->div ({ class=>"spLeft" }, [
255
      $h->div ({ class=>"footer" }, [
273
      $h->div ({ class=>"footer" }, [
-
 
274
        "To bookmark, save, or send this exact view, use the ",
-
 
275
        $h->a ({ href=>'', onClick=>"window.document.Req.method = 'GET'; Req.submit(); return false;" }, "[Full URL]"),
-
 
276
        $h->br,
256
        "To bookmark, save, or send this exact view, use the ",
277
        "If this page is displaying oddly, ",
257
        $h->a ({ href=>'', onClick=>"window.document.Req.method = 'GET'; Req.submit(); return false;" }, "[Full URL]"),
278
        $h->a ({ href=>url ()."?ignoreCookie=1" }, "[Reset Your View]"),
258
        $h->br,
279
        $h->br,
259
        "This page was displayed on $now",
280
        "This page was displayed on $now",
260
        $h->br,
281
        $h->br,
261
        "Please direct questions, problems, and concerns to noone\@gmail.com"
282
        "Please direct questions, problems, and concerns to noone\@gmail.com"
-
 
283
      ])
262
      ])
284
    ]),
-
 
285
    $h->div ({ class=>"spRight" }, [
-
 
286
      $h->h5 ([
-
 
287
               "$x of $datacount Record". ($x == 1 ? "" : "s") ." Displayed", $h->br,               
-
 
288
               "Sorted by ", $sortby, $h->br,
-
 
289
               "Displaying ", $h->select ({ name=>"limit", onChange=>"page.value = 1; submit();" }, [ map { $pagelimit == $_ ? $h->option ({ selected=>[] }, $_) : $h->option ($_) } @pagelimitoptions ]),
263
    ]),
290
               ( $pages > 1 ? " Per Page: ". ( join " ", map { $_ == $curpage ? "<B>$_</b>" : $h->a ({ onClick=>qq{Req.page.value=$_; Req.submit();} }, "[$_]") } (1 .. $pages) ) : "" ), $h->br,
264
    $h->div ({ class=>"spRight" }, [
291
               $h->input ({ type=>"hidden", name=>"page", value=>$curpage })
Line 265... Line 292...
265
      $h->h5 ("$x Record". ($x == 1 ? "" : "s") ." Displayed")
292
      ])
266
    ]),
293
    ]),