Diff for /loncom/interface/coursecatalog.pm between versions 1.33 and 1.35

version 1.33, 2008/06/30 04:07:06 version 1.35, 2008/07/06 17:59:25
Line 71  sub handler { Line 71  sub handler {
     }      }
     my $domdesc = &Apache::lonnet::domain($codedom,'description');      my $domdesc = &Apache::lonnet::domain($codedom,'description');
     &Apache::lonhtmlcommon::clear_breadcrumbs();      &Apache::lonhtmlcommon::clear_breadcrumbs();
   
       my %domconfig =
           &Apache::lonnet::get_dom('configuration',['coursecategories'],$codedom);
       my (@cats,@trails,%allitems,%idx,@jsarray,$cathash);
       if (ref($domconfig{'coursecategories'}) eq 'HASH') {
           $cathash = $domconfig{'coursecategories'}{'cats'};
       } else {
           $cathash = {};
       }
       &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems,
                                              \%idx,\@jsarray);
     if ($env{'form.coursenum'} ne '' && &user_is_known()) {      if ($env{'form.coursenum'} ne '' && &user_is_known()) {
         &course_details($r,$codedom,$formname,$domdesc);          &course_details($r,$codedom,$formname,$domdesc,\@trails,\%allitems);
     } else {      } else {
         my $catlinks = &category_breadcrumbs($codedom);          my $catlinks = &category_breadcrumbs($codedom,@cats);
         my $catjs = <<"ENDSCRIPT";          my $catjs = <<"ENDSCRIPT";
   
 function setCatDepth(depth) {  function setCatDepth(depth) {
Line 125  function setCourseId(caller) { Line 136  function setCourseId(caller) {
                           &mt('Display courses').'" /></form><br /><br />');                            &mt('Display courses').'" /></form><br /><br />');
             }              }
             if ($env{'form.state'} eq 'listing') {              if ($env{'form.state'} eq 'listing') {
                 $r->print(&print_course_listing($codedom));                  $r->print(&print_course_listing($codedom,undef,\@trails,\%allitems));
             }              }
         }          }
     }      }
Line 134  function setCourseId(caller) { Line 145  function setCourseId(caller) {
 }  }
   
 sub course_details {  sub course_details {
     my ($r,$codedom,$formname,$domdesc) = @_;      my ($r,$codedom,$formname,$domdesc,$trails,$allitems) = @_;
     my $output;      my $output;
     my %add_entries = (topmargin    => "0",      my %add_entries = (topmargin    => "0",
                        marginheight => "0",);                         marginheight => "0",);
Line 156  sub course_details { Line 167  sub course_details {
     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course Details'));      $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course Details'));
     $r->print('<br />'.&mt('Detailed course information:').'<br /><br />'.      $r->print('<br />'.&mt('Detailed course information:').'<br /><br />'.
               '<form name="'.$formname.'" method="post">'.                '<form name="'.$formname.'" method="post">'.
               &print_course_listing($codedom).'<br /><br />');                &print_course_listing($codedom,undef,$trails,$allitems).
                 '<br /><br />');
     $r->print('<a href = "javascript:document.coursecatalog.submit()">'.      $r->print('<a href = "javascript:document.coursecatalog.submit()">'.
               &mt('Back to course listing').'</a>'.                &mt('Back to course listing').'</a>'.
               '<input type="hidden" name="sortby" value="'.                '<input type="hidden" name="sortby" value="'.
Line 341  sub cat_header { Line 353  sub cat_header {
           text=>"Select courses"});            text=>"Select courses"});
         $r->print(&Apache::lonhtmlcommon::breadcrumbs('Select courses'));          $r->print(&Apache::lonhtmlcommon::breadcrumbs('Select courses'));
     }      }
     $r->print('<table border="0"><tr>'.      $r->print('<form name="coursecatdom" method="post" action="/adm/coursecatalog">'.
               '<form name="coursecatdom" method="post" action="/adm/coursecatalog">'.                '<table border="0"><tr><td><b>'.&mt('Domain:').'</b></td><td>'.
               '<td><b>'.&mt('Domain:').'</b></td><td>'.  
               &Apache::loncommon::select_dom_form($codedom,'showdom','',1).                &Apache::loncommon::select_dom_form($codedom,'showdom','',1).
       '&nbsp;<input type="submit" name="godom" value="'.&mt('Change').'"></td></form></tr>'.        '&nbsp;<input type="submit" name="godom" value="'.&mt('Change').'" /></td></tr></table></form>'.
       '<tr><form name="coursecats" method="post" action="/adm/coursecatalog">'.        '<form name="coursecats" method="post" action="/adm/coursecatalog">'.
               $catlinks.'</form></tr></table>');                '<table border="0"><tr>'.$catlinks.'</tr></table></form>');
     return;      return;
 }  }
   
 sub category_breadcrumbs {  sub category_breadcrumbs {
     my ($dom) = @_;      my ($dom,@cats) = @_;
     my %domconfig =  
         &Apache::lonnet::get_dom('configuration',['coursecategories'],$dom);  
     my (@cats,@trails,%allitems,%idx,@jsarray,$cathash);  
     if (ref($domconfig{'coursecategories'}) eq 'HASH') {  
         $cathash = $domconfig{'coursecategories'}{'cats'};  
     } else {  
         $cathash = {};  
     }  
     &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,  
                                            \@jsarray);  
     my ($currdepth,$deeper) = &get_depth_values();      my ($currdepth,$deeper) = &get_depth_values();
     my $currcat_str = '<input type="hidden" name="catalog_maxdepth" value="'.$deeper.'" /><input type="hidden" name="showdom" value="'.$dom.'" />';      my $currcat_str = '<input type="hidden" name="catalog_maxdepth" value="'.$deeper.'" /><input type="hidden" name="showdom" value="'.$dom.'" />';
     my $catlinks = '<td valign="top"><b>'.&mt('Catalog:').'</b></td><td><table><tr>';      my $catlinks = '<td valign="top"><b>'.&mt('Catalog:').'</b></td><td><table><tr>';
Line 383  sub category_breadcrumbs { Line 384  sub category_breadcrumbs {
         if (ref($cats[0]) eq 'ARRAY') {          if (ref($cats[0]) eq 'ARRAY') {
             if ((@{$cats[0]} == 1) && ($cats[0][0] eq 'instcode')) {              if ((@{$cats[0]} == 1) && ($cats[0][0] eq 'instcode')) {
                 $catlinks .= &mt('Official courses (with institutional codes)').                  $catlinks .= &mt('Official courses (with institutional codes)').
                              '<input type="hidden" name="currcat_0" value="instcode::0">';                               '<input type="hidden" name="currcat_0" value="instcode::0" />';
                 $env{'form.currcat_0'} = 'instcode::0';                  $env{'form.currcat_0'} = 'instcode::0';
             } else {              } else {
                 $catlinks .= '<select name="currcat_0">'."\n";                  $catlinks .= '<select name="currcat_0">'."\n";
Line 414  sub category_breadcrumbs { Line 415  sub category_breadcrumbs {
             }              }
         } else {          } else {
             $catlinks .= &mt('Official courses (with institutional codes)').              $catlinks .= &mt('Official courses (with institutional codes)').
                          '<input type="hidden" name="currcat_0" value="instcode::0">';                           '<input type="hidden" name="currcat_0" value="instcode::0" />';
             $env{'form.currcat_0'} = 'instcode::0';              $env{'form.currcat_0'} = 'instcode::0';
         }          }
     } else {      } else {
Line 650  sub search_courselist { Line 651  sub search_courselist {
 }  }
   
 sub print_course_listing {  sub print_course_listing {
     my ($domain,$numtitles) = @_;      my ($domain,$numtitles,$trails,$allitems) = @_;
     my $output;      my $output;
     my %courses;      my %courses;
     my $knownuser = &user_is_known();      my $knownuser = &user_is_known();
Line 687  sub print_course_listing { Line 688  sub print_course_listing {
     my $now = time;      my $now = time;
     my %domconfig =      my %domconfig =
         &Apache::lonnet::get_dom('configuration',['usercreation'],$domain);          &Apache::lonnet::get_dom('configuration',['usercreation'],$domain);
     $output .= &construct_data_table($knownuser,\%courses,$details,undef,$now,\%domconfig);      $output .= &construct_data_table($knownuser,\%courses,$details,undef,$now,\%domconfig,$trails,$allitems);
     $output .= &Apache::lonhtmlcommon::echo_form_input(['coursenum','state','catalogfilter','sortby','showdetails']);      $output .= &Apache::lonhtmlcommon::echo_form_input(['coursenum','state','catalogfilter','sortby','showdetails']);
     return $output;      return $output;
 }  }
   
 sub construct_data_table {  sub construct_data_table {
     my ($knownuser,$courses,$details,$usersections,$now,$domconfig) = @_;      my ($knownuser,$courses,$details,$usersections,$now,$domconfig,$trails,
           $allitems) = @_;
     my %sortname;      my %sortname;
     if (($details eq '') || ($env{'form.showdetails'})) {      if (($details eq '') || ($env{'form.showdetails'})) {
         $sortname{'Code'} = 'code';          $sortname{'Code'} = 'code';
           $sortname{'Categories'} = 'cats';
         $sortname{'Title'} = 'title';          $sortname{'Title'} = 'title';
         $sortname{'Owner(s)'} = 'owner';          $sortname{'Owner(s)'} = 'owner';
     }      }
     my $output = &Apache::loncommon::start_data_table().      my $output = &Apache::loncommon::start_data_table().
                  &Apache::loncommon::start_data_table_header_row();                   &Apache::loncommon::start_data_table_header_row();
     my @coltitles = ('Count','Code','Sections','Crosslisted','Title','Owner(s)');      my @coltitles = ('Count');
       if ($env{'form.currcat_0'} eq 'instcode::0') {
           push(@coltitles,'Code');
       } else {
           push(@coltitles,'Categories');
       }
       push(@coltitles,('Sections','Crosslisted','Title','Owner(s)'));
     if (ref($usersections) eq 'HASH') {      if (ref($usersections) eq 'HASH') {
        $coltitles[1] = 'Your Section';         $coltitles[1] = 'Your Section';
     }      }
Line 735  sub construct_data_table { Line 744  sub construct_data_table {
     foreach my $course (sort(keys(%{$courses}))) {      foreach my $course (sort(keys(%{$courses}))) {
         if ($env{'form.sortby'} eq 'code') {          if ($env{'form.sortby'} eq 'code') {
             push(@{$Sortby{$courseinfo{$course}{'code'}}},$course);              push(@{$Sortby{$courseinfo{$course}{'code'}}},$course);
           } elsif ($env{'form.sortby'} eq 'cats') {
               push(@{$Sortby{$courseinfo{$course}{'categories'}}},$course);
         } elsif ($env{'form.sortby'} eq 'owner') {          } elsif ($env{'form.sortby'} eq 'owner') {
             push(@{$Sortby{$courseinfo{$course}{'ownerlastnames'}}},$course);              push(@{$Sortby{$courseinfo{$course}{'ownerlastnames'}}},$course);
         } else {          } else {
Line 747  sub construct_data_table { Line 758  sub construct_data_table {
         }          }
     }      }
     my @sorted_courses;      my @sorted_courses;
     if (($env{'form.sortby'} eq 'code') || ($env{'form.sortby'} eq 'owner')) {      if (($env{'form.sortby'} eq 'code') || ($env{'form.sortby'} eq 'owner') ||
           ($env{'form.sortby'} eq 'cats')) {
         @sorted_courses = sort(keys(%Sortby));          @sorted_courses = sort(keys(%Sortby));
     } else {      } else {
         @sorted_courses = sort { lc($a) cmp lc($b) } (keys(%Sortby));          @sorted_courses = sort { lc($a) cmp lc($b) } (keys(%Sortby));
Line 756  sub construct_data_table { Line 768  sub construct_data_table {
     foreach my $item (@sorted_courses) {      foreach my $item (@sorted_courses) {
         foreach my $course (@{$Sortby{$item}}) {          foreach my $course (@{$Sortby{$item}}) {
             $output.=&Apache::loncommon::start_data_table_row();               $output.=&Apache::loncommon::start_data_table_row(); 
             $output.=&courseinfo_row($courseinfo{$course},$knownuser,              $output.=&courseinfo_row($courseinfo{$course},$knownuser,$details,
                                      $details,\$count,$now,$course);                                       \$count,$now,$course,$trails,$allitems);
             $output.=&Apache::loncommon::end_data_table_row();              $output.=&Apache::loncommon::end_data_table_row();
         }          }
     }      }
Line 779  sub build_courseinfo_hash { Line 791  sub build_courseinfo_hash {
         $cleandesc =~ s/^\s+//;          $cleandesc =~ s/^\s+//;
         my ($cdom,$cnum)=split(/\_/,$course);          my ($cdom,$cnum)=split(/\_/,$course);
         my ($descr,$instcode,$singleowner,$ttype,$selfenroll_types,          my ($descr,$instcode,$singleowner,$ttype,$selfenroll_types,
             $selfenroll_start,$selfenroll_end,@owners,%ownernames);              $selfenroll_start,$selfenroll_end,@owners,%ownernames,$categories);
         if (ref($courses->{$course}) eq 'HASH') {          if (ref($courses->{$course}) eq 'HASH') {
             $descr = $courses->{$course}{'description'};              $descr = $courses->{$course}{'description'};
             $instcode =  $courses->{$course}{'inst_code'};              $instcode =  $courses->{$course}{'inst_code'};
Line 788  sub build_courseinfo_hash { Line 800  sub build_courseinfo_hash {
             $selfenroll_types = $courses->{$course}{'selfenroll_types'};              $selfenroll_types = $courses->{$course}{'selfenroll_types'};
             $selfenroll_start = $courses->{$course}{'selfenroll_start_date'};              $selfenroll_start = $courses->{$course}{'selfenroll_start_date'};
             $selfenroll_end = $courses->{$course}{'selfenroll_end_date'};              $selfenroll_end = $courses->{$course}{'selfenroll_end_date'};
               $categories = $courses->{$course}{'categories'};
             push(@owners,$singleowner);              push(@owners,$singleowner);
             if (ref($courses->{$course}{'co-owners'}) eq 'ARRAY') {              if (ref($courses->{$course}{'co-owners'}) eq 'ARRAY') {
                 foreach my $item (@{$courses->{$course}{'co-owners'}}) {                  foreach my $item (@{$courses->{$course}{'co-owners'}}) {
Line 825  sub build_courseinfo_hash { Line 838  sub build_courseinfo_hash {
         $courseinfo{$course}{'selfenroll_types'} = $selfenroll_types;          $courseinfo{$course}{'selfenroll_types'} = $selfenroll_types;
         $courseinfo{$course}{'selfenroll_start'} = $selfenroll_start;          $courseinfo{$course}{'selfenroll_start'} = $selfenroll_start;
         $courseinfo{$course}{'selfenroll_end'} = $selfenroll_end;          $courseinfo{$course}{'selfenroll_end'} = $selfenroll_end;
           $courseinfo{$course}{'categories'} = $categories;
   
         my %coursehash = &Apache::lonnet::dump('environment',$cdom,$cnum);          my %coursehash = &Apache::lonnet::dump('environment',$cdom,$cnum);
         my @classids;          my @classids;
Line 860  sub build_courseinfo_hash { Line 874  sub build_courseinfo_hash {
             if ( defined($coursehash{'default_enrollment_end_date'}) ) {              if ( defined($coursehash{'default_enrollment_end_date'}) ) {
                 $endaccess = &Apache::lonlocal::locallocaltime($coursehash{'default_enrollment_end_date'});                  $endaccess = &Apache::lonlocal::locallocaltime($coursehash{'default_enrollment_end_date'});
                 if ($coursehash{'default_enrollment_end_date'} == 0) {                  if ($coursehash{'default_enrollment_end_date'} == 0) {
                     $endaccess = "No ending date";                      $endaccess = &mt('No ending date');
                 }                  }
             }              }
             if ($startaccess) {              if ($startaccess) {
Line 869  sub build_courseinfo_hash { Line 883  sub build_courseinfo_hash {
             if ($endaccess) {              if ($endaccess) {
                 $accessdates .= &mt('<i>To:</i> ').$endaccess.'<br />';                  $accessdates .= &mt('<i>To:</i> ').$endaccess.'<br />';
             }              }
               if (($selfenroll_types ne '') && 
                   ($selfenroll_end > 0 && $selfenroll_end > $now)) {
                   my ($selfenroll_start_access,$selfenroll_end_access);
                   if (($coursehash{'default_enrollment_start_date'} ne 
                        $coursehash{'internal.selfenroll_start_access'}) ||
                      ($coursehash{'default_enrollment_end_date'} ne 
                       $coursehash{'internal.selfenroll_end_access'})) {
                       if ( defined($coursehash{'internal.selfenroll_start_access'}) ) {
                           $selfenroll_start_access = &Apache::lonlocal::locallocaltime($coursehash{'internal.selfenroll_start_access'});
                       }
                       if ( defined($coursehash{'default_enrollment_end_date'}) ) {
                           $selfenroll_end_access = &Apache::lonlocal::locallocaltime($coursehash{'internal.selfenroll_end_access'});
                           if ($coursehash{'internal.selfenroll_end_access'} == 0) {
                               $selfenroll_end_access = &mt('No ending date');
                           }
                       }
                       if ($selfenroll_start_access || $selfenroll_end_access) {
                           $accessdates .= '<br/><br /><i>'.&mt('Self-enrollers:').'</i><br />';
                           if ($selfenroll_start_access) {
                               $accessdates .= &mt('<i>From:</i> ').$selfenroll_start_access.'<br />';
                           }
                           if ($selfenroll_end_access) {
                               $accessdates .= &mt('<i>To:</i> ').$selfenroll_end_access.'<br />';
                           }
                       }
                   }
               }
             $courseinfo{$course}{'access'} = $accessdates;              $courseinfo{$course}{'access'} = $accessdates;
         }          }
         if ($xlist_items eq '') {          if ($xlist_items eq '') {
Line 908  sub count_students { Line 949  sub count_students {
 }  }
   
 sub courseinfo_row {  sub courseinfo_row {
     my ($info,$knownuser,$details,$countref,$now,$course) = @_;      my ($info,$knownuser,$details,$countref,$now,$course,$trails,$allitems) = @_;
     my ($cdom,$cnum,$title,$ownerlast,$code,$owner,$seclist,$xlist_items,      my ($cdom,$cnum,$title,$ownerlast,$code,$owner,$seclist,$xlist_items,
         $accessdates,$showsyllabus,$counts,$autoenrollment,$output);          $accessdates,$showsyllabus,$counts,$autoenrollment,$output,$categories);
     if (ref($info) eq 'HASH') {      if (ref($info) eq 'HASH') {
         $cdom = $info->{'cdom'};          $cdom = $info->{'cdom'};
         $cnum = $info->{'cnum'};          $cnum = $info->{'cnum'};
Line 924  sub courseinfo_row { Line 965  sub courseinfo_row {
         $counts = $info->{'counts'};          $counts = $info->{'counts'};
         $autoenrollment = $info->{'autoenrollment'};          $autoenrollment = $info->{'autoenrollment'};
         $showsyllabus = $info->{'showsyllabus'};          $showsyllabus = $info->{'showsyllabus'};
           $categories = $info->{'categories'};
     } else {      } else {
         $output = '<td colspan="8">'.&mt('No information available for [_1].',          $output = '<td colspan="8">'.&mt('No information available for [_1].',
                                          $code).'</td>';                                           $code).'</td>';
         return $output;          return $output;
     }      }
     $output .= '<td>'.$$countref.'</td>'.      $output .= '<td>'.$$countref.'</td>';
                '<td>'.$code.'</td>'.      if ($env{'form.currcat_0'} eq 'instcode::0') {
                '<td>'.$seclist.'</td>'.          $output .= '<td>'.$code.'</td>';
       } else {
           my ($categorylist,@cats);
           if ($categories ne '') {
               @cats = split('&',$categories);
           }
           if ((ref($trails) eq 'ARRAY') && (ref($allitems) eq 'HASH')) {
               my @categories = map { $trails->[$allitems->{$_}]; } @cats;
               $categorylist = join('<br />',@categories);
           }
           if ($categorylist eq '') {
               $categorylist = '&nbsp;';
           }
           $output .= '<td>'.$categorylist.'</td>';
       }
       $output .= '<td>'.$seclist.'</td>'.
                '<td>'.$xlist_items.'</td>'.                 '<td>'.$xlist_items.'</td>'.
                '<td>'.$title.'&nbsp;<font size="-2">';                 '<td>'.$title.'&nbsp;<font size="-2">';
     if ($showsyllabus) {      if ($showsyllabus) {

Removed from v.1.33  
changed lines
  Added in v.1.35


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>