[LON-CAPA-cvs] cvs: loncom /cgi quotacheck.pl
raeburn
raeburn at source.lon-capa.org
Mon May 4 11:13:57 EDT 2015
raeburn Mon May 4 15:13:57 2015 EDT
Modified files:
/loncom/cgi quotacheck.pl
Log:
- Don't display unfiltered search results on initial load.
- Eliminate javascript error on load when selected course type is Community.
- Support sortby, sortorder, and type (official, unofficial, or Community)
in query string when IP-based access in use.
- Omit instcode column unless displaying quotas for any course type,
or for official courses only.
-------------- next part --------------
Index: loncom/cgi/quotacheck.pl
diff -u loncom/cgi/quotacheck.pl:1.7 loncom/cgi/quotacheck.pl:1.8
--- loncom/cgi/quotacheck.pl:1.7 Sat Aug 23 18:54:45 2014
+++ loncom/cgi/quotacheck.pl Mon May 4 15:13:57 2015
@@ -6,7 +6,7 @@
# requested domain, or current server should belong to requested
# domain.
#
-# $Id: quotacheck.pl,v 1.7 2014/08/23 18:54:45 raeburn Exp $
+# $Id: quotacheck.pl,v 1.8 2015/05/04 15:13:57 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -36,6 +36,7 @@
use lib '/home/httpd/lib/perl/';
use Apache::lonnet();
use Apache::loncommon();
+use Apache::courseclassifier();
use Apache::lonlocal();
use LONCAPA::Configuration();
use LONCAPA::loncgi();
@@ -85,7 +86,7 @@
return;
}
}
- my (%gets,%posted,$reqdom,$crstype,%params);
+ my ($reqdom,$crstype,$type,%params);
#
# Get domain -- if this is for an authenticated user (i.e., not IP-based access)
@@ -99,11 +100,12 @@
$crstype = 'Course';
if ($params{'type'} eq 'Community') {
$crstype = $params{'type'};
+ $type = $crstype;
}
if ($params{'fixeddom'}) { $reqdom = $params{'fixeddom'} }
- unless ($params{'sortby'}) { $params{'sortby'} = 'cdesc'; }
}
if (($reqdom eq '') && ($ENV{'QUERY_STRING'})) {
+ my %gets;
&LONCAPA::loncgi::cgi_getitems($ENV{'QUERY_STRING'},\%gets);
if (ref($gets{'domain'}) eq 'ARRAY') {
$gets{'domain'}->[0] =~ s/^\s+|\s+$//g;
@@ -114,41 +116,62 @@
}
}
}
+ if (($crstype eq '') && (ref($gets{'type'}) eq 'ARRAY')) {
+ $gets{'type'}->[0] =~ s/^\s+|\s+$//g;
+ if (lc($gets{'type'}->[0]) eq 'community') {
+ $crstype = 'Community';
+ } elsif ($gets{'type'}->[0] =~ /^(un|)official$/) {
+ $crstype = $gets{'type'}->[0];
+ }
+ }
+ if (($params{'sortby'} eq '') && (ref($gets{'sortby'}) eq 'ARRAY')){
+ $gets{'sortby'}->[0] =~ s/^\s+|\s+$//g;
+ if ($gets{'sortby'}->[0] =~ /^(quota|current_disk_usage|percent|quotatype|instcode)$/) {
+ $params{'sortby'} = $1;
+ }
+ }
+ if (($params{'sortorder'} eq '') && (ref($gets{'sortorder'}) eq 'ARRAY')){
+ $gets{'sortorder'}->[0] =~ s/^\s+|\s+$//g;
+ if ($gets{'sortorder'}->[0] eq 'rev') {
+ $params{'sortorder'} = $gets{'sortorder'}->[0];
+ }
+ }
}
if ($reqdom eq '') {
$reqdom = &Apache::lonnet::default_login_domain();
}
-
+ my $knownuser;
+ if (($Apache::lonnet::env{'user.name'}) && ($Apache::lonnet::env{'user.domain'})) {
+ $knownuser = 1;
+ }
&Apache::lonlocal::get_language_handle();
&Apache::lonhtmlcommon::add_breadcrumb
({href=>$script."?domain=$reqdom",
text=>"Content disk usage"});
- if ( ($params{'gosearch'}) || ($params{'sortby'}) ) {
+ if ((($params{'gosearch'}) || ($params{'sortby'})) && ($knownuser)) {
&Apache::lonhtmlcommon::add_breadcrumb
({href=>$script."?domain=$reqdom",
text=>"Result"});
}
my $domdesc = &Apache::lonnet::domain($reqdom,'description');
- my $starthash = {
- add_entries => {'onload' => "javascript:courseSet(document.filterpicker.official, 'load');"},
- };
+ my $starthash;
+ unless ($crstype eq 'Community') {
+ $starthash = {
+ add_entries => {'onload' => "javascript:courseSet(document.filterpicker.official, 'load');"},
+ };
+ }
print(&Apache::loncommon::start_page('Course/Community disk usage and quotas', undef, $starthash).
&Apache::lonhtmlcommon::breadcrumbs('Course/Community status').
'<h2>'.&Apache::lonlocal::mt('Quotas for uploaded course content').'</h2>'.
'<h3>'.$domdesc.'</h3>');
- my $changejs = <<"ENDSCRIPT";
-<script>
-function changeSort(sortby) {
- document.filterpicker.sortby.value = sortby;
- if (('$params{'sortby'}' == sortby) && ('$params{'sortorder'}' != 'rev')) {
- document.filterpicker.sortorder.value = 'rev';
- }
- document.filterpicker.submit();
-}
-</script>
-ENDSCRIPT
- print($changejs);
+# Sort by course title (cdesc) as default, not reversed
+ my $sortby = $params{'sortby'};
+ unless ($sortby =~ m{^(quota|current_disk_usage|percent|quotatype|instcode)$}) {
+ $sortby = 'cdesc';
+ }
+ my $sortorder;
+ if ($params{'sortorder'} eq 'rev') { $sortorder = 'rev'; }
#
# If this is for an authenticated user (i.e., not IP-based access)
@@ -156,7 +179,18 @@
# (e.g., recent activity, recently created, institutional code, course owner etc.)
#
- if (($Apache::lonnet::env{'user.name'}) && ($Apache::lonnet::env{'user.domain'})) {
+ if ($knownuser) {
+ print <<"ENDSCRIPT";
+<script>
+function changeSort(sortby) {
+ document.filterpicker.sortby.value = sortby;
+ if (('$sortby' == sortby) && ('$params{'sortorder'}' != 'rev')) {
+ document.filterpicker.sortorder.value = 'rev';
+ }
+ document.filterpicker.submit();
+}
+</script>
+ENDSCRIPT
my ($numtitles, at codetitles);
print(&Apache::loncommon::js_changer());
my ($filterlist,$filter) = &get_filters($reqdom,\%params);
@@ -167,8 +201,10 @@
foreach my $item (@standardnames) {
if ($params{'official'} eq 'on') {
$Apache::lonnet::env{'form.'.$item} = $params{$item};
+ $type = 'official';
} else {
$Apache::lonnet::env{'form.'.$item} = 0;
+ $type = 'unofficial';
}
}
$Apache::lonnet::env{'form.state'} = $params{'state'};
@@ -181,30 +217,52 @@
if ($params{'official'} eq 'on') {
$Apache::lonnet::env{'form.state'} = $params{'state'};
}
- # Sort by course title (cdesc) as default, not reversed
- my $sortby = $params{'sortby'};
- unless ($sortby =~ m{^(quota|current_disk_usage|percent|quotatype|instcode)$}) {
- $sortby = 'cdesc';
- }
- my $sortorder;
- if ($params{'sortorder'} eq 'rev') { $sortorder = 'rev'; }
-
my %courses = &Apache::loncommon::search_courses($reqdom,$crstype,$filter,$numtitles,
undef,undef,undef,\@codetitles);
my @showcourses = keys(%courses);
- &print_usage($lonhost,$reqdom,\@showcourses,$sortby,$sortorder);
+ &print_usage($lonhost,$reqdom,\@showcourses,$sortby,$sortorder,$type,
+ $knownuser,$script);
}
-
- print(&Apache::loncommon::end_page());
- return;
+ } else {
+ my ($instcodefilter,$regexpok, at showcourses);
+ $instcodefilter = '.';
+ if ($crstype eq '') {
+ $crstype = '.';
+ } elsif ($crstype =~ /^(un|)official$/) {
+ $type = $crstype;
+ my ($numtitles, at codetitles,%cat_items,%cat_titles,%cat_order);
+ (undef,undef,$numtitles) =
+ &Apache::courseclassifier::instcode_selectors_data($reqdom,'filterpicker',
+ \%cat_items,\@codetitles,
+ \%cat_titles,\%cat_order);
+ foreach my $item (@codetitles) {
+ $Apache::lonnet::env{'form.'.$item} = 0;
+ }
+ $instcodefilter =
+ &Apache::courseclassifier::instcode_search_str($reqdom,$numtitles,\@codetitles);
+ if ($crstype eq 'official') {
+ $regexpok = 1;
+ } elsif ($crstype eq 'unofficial') {
+ unless ($instcodefilter eq '') {
+ $regexpok = -1;
+ }
+ }
+ $crstype = 'Course';
+ }
+ my %courseshash = &Apache::lonnet::courseiddump($reqdom,'.',1,$instcodefilter,'.','.',
+ undef,undef,$crstype,$regexpok);
+ if (keys(%courseshash)) {
+ @showcourses = keys(%courseshash);
+ }
+ &print_usage($lonhost,$reqdom,\@showcourses,$sortby,$sortorder,$type,$knownuser,
+ $script);
}
- &print_usage($lonhost,$reqdom);
print(&Apache::loncommon::end_page());
return;
}
sub print_usage {
- my ($lonhost,$dom,$courses,$sortby,$sortorder) = @_;
+ my ($lonhost,$dom,$courses,$sortby,$sortorder,$type,$knownuser,$script) = @_;
my @domains = &Apache::lonnet::current_machine_domains();
my @ids=&Apache::lonnet::current_machine_ids();
my $domain = &Apache::lonnet::host_domain($lonhost);
@@ -285,6 +343,7 @@
# Print column headers
my $output = '';
foreach my $key (@order) {
+ next if (($key eq 'instcode') && ($type ne 'official') && ($type ne ''));
my $idx;
# Append an up or down arrow to sorted column
if ($sortby eq $key) {
@@ -292,9 +351,20 @@
if ($sortorder eq 'rev') { $idx ++; }
$idx = $idx%2;
} else { $idx = 2; } # No arrow if column not sorted
- $output .= '<th><a href="javascript:changeSort('
- ."'$key'".');">'.$columns{$key}{text}
- .$arrows[$idx].'</a></th>';
+ my $link = 'javascript:changeSort('."'$key'".');';
+ if (!$knownuser) {
+ $link = $script.'?domain='.$dom.'&sortby='.$key;
+ if ($type =~ /^((un|)official)|(C|c)ommunity/) {
+ $link .='&type='.$type;
+ }
+ if ($sortby eq $key) {
+ unless ($sortorder) {
+ $link .= '&sortorder=rev';
+ }
+ }
+ }
+ $output .= '<th><a href="'.$link.'"">'.$columns{$key}{text}
+ .$arrows[$idx].'</a></th>';
}
print(&Apache::loncommon::start_data_table()
.&Apache::loncommon::start_data_table_header_row().$output
@@ -411,9 +481,11 @@
foreach my $course (@sorted_courses) {
print(&Apache::loncommon::start_data_table_row().
'<td>'.$usagehash->{$course}->{"quotatype"}.'</td>'.
- '<td>'.$usagehash->{$course}->{"cdesc"}.'</td>'.
- '<td>'.$usagehash->{$course}->{"instcode"}.'</td>'.
- '<td>'.$usagehash->{$course}->{"quota"}.'</td>'.
+ '<td>'.$usagehash->{$course}->{"cdesc"}.'</td>');
+ if (($type eq 'official') || (!$type)) {
+ print('<td>'.$usagehash->{$course}->{"instcode"}.'</td>');
+ }
+ print('<td>'.$usagehash->{$course}->{"quota"}.'</td>'.
'<td>'.$usagehash->{$course}->{"current_disk_usage"}.'</td>'.
'<td>'.$usagehash->{$course}->{"percent"}.'</td>'.
&Apache::loncommon::end_data_table_row()
More information about the LON-CAPA-cvs
mailing list