[LON-CAPA-cvs] cvs: loncom /interface coursecatalog.pm
raeburn
lon-capa-cvs@mail.lon-capa.org
Fri, 12 Jan 2007 23:37:23 -0000
This is a MIME encoded message
--raeburn1168645043
Content-Type: text/plain
raeburn Fri Jan 12 18:37:23 2007 EDT
Modified files:
/loncom/interface coursecatalog.pm
Log:
bug 5135. Addresses case where a domain has assigned institutional codes to at least one course, but has not customized the instcode_format() subroutine in localenroll.pm (provided as a stub).
If no category titles have been defined in localenroll::instcode_format(), coursecatalog now displays a listing of all courses in the domain which have
institutional codes.
In the absence of defined categories, there is no "Choose which course(s) to list.", no select boxes and no "Display courses" button. Sorting by code, title or owner no longer generates javascript errors in this case.
The prior behavior - display of "No official courses to display for <Domain Name>" - when there are no courses with institutional codes, is still the same.
--raeburn1168645043
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20070112183723.txt"
Index: loncom/interface/coursecatalog.pm
diff -u loncom/interface/coursecatalog.pm:1.17 loncom/interface/coursecatalog.pm:1.18
--- loncom/interface/coursecatalog.pm:1.17 Fri Jan 12 16:07:37 2007
+++ loncom/interface/coursecatalog.pm Fri Jan 12 18:37:22 2007
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler for displaying the course catalog interface
#
-# $Id: coursecatalog.pm,v 1.17 2007/01/12 21:07:37 albertel Exp $
+# $Id: coursecatalog.pm,v 1.18 2007/01/12 23:37:22 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -67,10 +67,10 @@
if ($env{'form.coursenum'} ne '' && &user_is_known()) {
&course_details($r,$codedom,$formname,$domdesc);
} else {
- &course_selector($r,$codedom,$formname,$domdesc);
+ my $numtitles = &course_selector($r,$codedom,$formname,$domdesc);
if ($env{'form.state'} eq 'listing') {
- $r->print('<br /><br />'.&print_course_listing($codedom).'<br />');
- }
+ $r->print(&print_course_listing($codedom,$numtitles).'<br />');
+ }
}
$r->print(&Apache::loncommon::end_page());
return OK;
@@ -137,41 +137,49 @@
if ($numtitles > 4) {
$lasttitle = 4;
}
- my @data = ('top');
- for (my $k=0; $k<$lasttitle; $k++) {
- my $cat = $codetitles[$k];
- my $level = 1;
- $level = &recurse_options($codetitles[$k],$idlist{$codetitles[$k]},$level,$cat,\%cat_items,\@data,\%by_year,\%by_sem,\%by_dept); }
- $scripttext .= &build_javascript(\%by_year,\%by_sem,\%by_dept,\%cat_order,\@codetitles);
- $jscript .= &javascript_select_filler($formname,$scripttext,\@codetitles,$longtitles_str,$allidlist);
- }
- if ($env{'form.state'} eq 'listing') {
- $jscript .= '
+ if ($numtitles == 0) {
+ if (!defined($env{'form.state'})) {
+ $env{'form.state'} = 'listing';
+ }
+ } else {
+ my @data = ('top');
+ for (my $k=0; $k<$lasttitle; $k++) {
+ my $cat = $codetitles[$k];
+ my $level = 1;
+ $level = &recurse_options($codetitles[$k],$idlist{$codetitles[$k]},$level,$cat,\%cat_items,\@data,\%by_year,\%by_sem,\%by_dept);
+ }
+ $scripttext .= &build_javascript(\%by_year,\%by_sem,\%by_dept,\%cat_order,\@codetitles);
+ $jscript .= &javascript_select_filler($formname,$scripttext,\@codetitles,$longtitles_str,$allidlist);
+ if ($env{'form.state'} eq 'listing') {
+ $jscript .= '
function setElements() {
';
- for (my $i=0; $i<@codetitles-1; $i++) {
- if ($env{'form.'.$codetitles[$i]} != -1) {
- $jscript .= '
+ for (my $i=0; $i<@codetitles-1; $i++) {
+ if ($env{'form.'.$codetitles[$i]} != -1) {
+ $jscript .= '
for (var j=0; j<document.'.$formname.'.'.$codetitles[$i].'.length; j++) {
if (document.'.$formname.'.'.$codetitles[$i].'[j].value == "'.$env{'form.'.$codetitles[$i]}.'") {
document.'.$formname.'.'.$codetitles[$i].'.selectedIndex = j;
}
}
';
- }
- }
- $jscript .= ' courseSet()'."\n";
- if ($env{'form.'.$codetitles[-1]} != -1) {
- $jscript .= '
+ }
+ }
+ $jscript .= ' courseSet()'."\n";
+ if ($env{'form.'.$codetitles[-1]} != -1) {
+ $jscript .= '
for (var j=0; j<document.'.$formname.'.'.$codetitles[-1].'.length; j++) {
if (document.'.$formname.'.'.$codetitles[-1].'[j].value == "'.$env{'form.'.$codetitles[-1]}.'") {
document.'.$formname.'.'.$codetitles[-1].'.selectedIndex = j;
}
}
';
+ }
+ $jscript .= '}';
+ }
}
- $jscript .= '}';
- $jscript .= qq|
+ if ($env{'form.state'} eq 'listing') {
+ $jscript .= qq|
function changeSort(caller) {
document.$formname.sortby.value = caller;
document.$formname.submit();
@@ -180,12 +188,13 @@
document.$formname.coursenum.value = caller;
document.$formname.submit();
}\n|;
+ }
}
my $js = '<script type"text/javascript">'."\n$jscript\n".
'</script>';
my %add_entries = (topmargin => "0",
marginheight => "0",);
- if ($env{'form.state'} eq 'listing') {
+ if (($env{'form.state'} eq 'listing') && ($numtitles > 0)) {
$add_entries{'onLoad'} = 'setElements()';
}
my $start_page =
@@ -207,9 +216,9 @@
$r->print(&Apache::lonhtmlcommon::breadcrumbs('Select courses'));
}
$r->print('<h3>'.&mt('Display information about official [_1] classes for which LON-CAPA courses have been created:',$domdesc).'</h3>');
- $r->print(&mt('<b>Choose which course(s) to list.</b><br />'));
$r->print('<form name="coursecatalog" method="post">');
if ($numtitles > 0) {
+ $r->print(&mt('<b>Choose which course(s) to list.</b><br />'));
$r->print('<table><tr>');
for (my $k=0; $k<$lasttitle-1; $k++) {
my @unsorted = @{$cat_items{$codetitles[$k]}};
@@ -252,15 +261,23 @@
$r->print('<br /><br />'.$codetitles[$numtitles-1].'<br />'."\n".
'<input type="text" name="'.$codetitles[$numtitles-1].'" /><br />'."\n");
}
+ $r->print('<br />');
+ }
+ $r->print('<input type="hidden" name="coursenum" value="" /><input type="hidden" name="sortby" value="" /><input type="hidden" name="state" value="listing" />');
+ if ($numtitles > 0) {
+ $r->print('<input type="submit" name="catalogfilter" value="'.&mt('Display courses').'" />');
+ }
+ $r->print('</form>');
+ if (($numtitles > 0) && ($env{'form.state'} eq 'listing')) {
+ $r->print('<br /><br />');
}
- $r->print('<br /><input type="hidden" name="coursenum" value="" /><input type="hidden" name="state" value="listing" /><input type="hidden" name="sortby" value="" /><input type="submit" name="catalogfilter" value="'.&mt('Display courses').'" /></form>');
} else {
$r->print(&Apache::loncommon::start_page('Course Catalog','',
{
'no_inline_link' => 1,}));
$r->print('<br />'.&mt('No official courses to display for [_1].',$domdesc));
}
- return;
+ return $numtitles;
}
sub user_is_dc {
@@ -360,23 +377,28 @@
}
sub search_courselist {
- my ($domain) = @_;
- my ($instcode,%codedefaults,@code_order);
- my $defaults_result =
- &Apache::lonnet::auto_instcode_defaults($domain,\%codedefaults,
- \@code_order);
- if ($defaults_result eq 'ok') {
- $instcode ='^';
- foreach my $item (@code_order) {
- if ($env{'form.'.$item} eq '0' ) {
- $instcode .= $codedefaults{$item};
- } else {
- $instcode .= $env{'form.'.$item};
+ my ($domain,$numtitles) = @_;
+ my $instcode;
+ if (defined($numtitles) && $numtitles == 0) {
+ $instcode = '.+';
+ } else {
+ my (%codedefaults,@code_order);
+ my $defaults_result =
+ &Apache::lonnet::auto_instcode_defaults($domain,\%codedefaults,
+ \@code_order);
+ if ($defaults_result eq 'ok') {
+ $instcode ='^';
+ foreach my $item (@code_order) {
+ if ($env{'form.'.$item} eq '0' ) {
+ $instcode .= $codedefaults{$item};
+ } else {
+ $instcode .= $env{'form.'.$item};
+ }
}
+ $instcode .= '$';
+ } else {
+ $instcode = '.';
}
- $instcode .= '$';
- } else {
- $instcode = '.';
}
my %courses = &Apache::lonnet::courseiddump($domain,'.',1,$instcode,'.','.',
undef,undef,'Course',1);
@@ -385,7 +407,7 @@
sub print_course_listing {
- my ($domain) = @_;
+ my ($domain,$numtitles) = @_;
my $output;
my %courses;
my $knownuser = &user_is_known();
@@ -404,7 +426,7 @@
return $output;
}
} else {
- %courses = &search_courselist($domain);
+ %courses = &search_courselist($domain,$numtitles);
if (keys(%courses) == 0) {
$output = &mt('No courses match the criteria you selected.');
return $output;
--raeburn1168645043--