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

version 1.28, 2008/05/29 04:29:33 version 1.33, 2008/06/30 04:07:06
Line 84  function setCatDepth(depth) { Line 84  function setCatDepth(depth) {
 }  }
   
 ENDSCRIPT  ENDSCRIPT
           if ($env{'form.state'} eq 'listing') {
               $catjs .= qq|
   function changeSort(caller) {
       document.$formname.sortby.value = caller;
       document.$formname.submit();
   }
   function setCourseId(caller) {
       document.$formname.coursenum.value = caller;
       document.$formname.submit();
   }\n|;
           }
         my $numtitles;          my $numtitles;
         if ($env{'form.currcat_0'} eq 'instcode::0') {          if ($env{'form.currcat_0'} eq 'instcode::0') {
             $numtitles = &instcode_course_selector($r,$codedom,$formname,$domdesc,              $numtitles = &instcode_course_selector($r,$codedom,$formname,$domdesc,
Line 96  ENDSCRIPT Line 107  ENDSCRIPT
             $catjs = '<script type="text/javascript">'."\n".$catjs."\n".'</script>';              $catjs = '<script type="text/javascript">'."\n".$catjs."\n".'</script>';
             &cat_header($r,$codedom,$catjs,\%add_entries,$catlinks);              &cat_header($r,$codedom,$catjs,\%add_entries,$catlinks);
             if ($env{'form.currcat_0'} ne '') {              if ($env{'form.currcat_0'} ne '') {
                   $r->print('<form name="'.$formname.
                             '" method="post" action="/adm/coursecatalog">'.
                             &additional_filters($codedom)."\n");
                   my ($currdepth,$deeper) = &get_depth_values();
                   $r->print('<input type="hidden" name="catalog_maxdepth" value="'.
                             $deeper.'" />'."\n");
                   for (my $i=0; $i<$deeper; $i++) {
                       $r->print('<input type="hidden" name="currcat_'.$i.'" value="'.$env{'form.currcat_'.$i}.'" />'."\n");
                   }
                   $r->print('<input type="hidden" name="coursenum" value="" />'."\n".
                             '<input type="hidden" name="sortby" value="" />'."\n".
                             '<input type="hidden" name="state" value="listing" />'."\n".
                             '<input type="hidden" name="showdom" value="'.
                             $env{'form.showdom'}.'" />'.
                             '<input type="submit" name="catalogfilter" value="'.
                             &mt('Display courses').'" /></form><br /><br />');
               }
               if ($env{'form.state'} eq 'listing') {
                 $r->print(&print_course_listing($codedom));                  $r->print(&print_course_listing($codedom));
             }              }
         }          }
     }      }
     $r->print(&Apache::loncommon::end_page());      $r->print('<br />'.&Apache::loncommon::end_page());
     return OK;      return OK;
 }  }
   
Line 154  sub instcode_course_selector { Line 183  sub instcode_course_selector {
     my $totcodes = 0;      my $totcodes = 0;
     my $jscript = '';      my $jscript = '';
     my ($numtitles,$lasttitle);      my ($numtitles,$lasttitle);
       my %add_entries = (topmargin    => "0",
                          marginheight => "0",);
       my $js;
     $totcodes = &Apache::courseclassifier::retrieve_instcodes(\%coursecodes,$codedom);      $totcodes = &Apache::courseclassifier::retrieve_instcodes(\%coursecodes,$codedom);
     if ($totcodes > 0) {      if ($totcodes > 0) {
         $format_reply = &Apache::lonnet::auto_instcode_format($caller,$codedom,\%coursecodes,\%codes,\@codetitles,\%cat_titles,\%cat_order);          $format_reply = &Apache::lonnet::auto_instcode_format($caller,$codedom,\%coursecodes,\%codes,\@codetitles,\%cat_titles,\%cat_order);
Line 209  function setElements() { Line 241  function setElements() {
                     $jscript .= '}';                      $jscript .= '}';
                 }                  }
             }              }
             if ($env{'form.state'} eq 'listing') {  
                 $jscript .= qq|  
 function changeSort(caller) {  
     document.$formname.sortby.value = caller;  
     document.$formname.submit();  
 }  
 function setCourseId(caller) {  
    document.$formname.coursenum.value = caller;  
    document.$formname.submit();   
 }\n|;  
             }  
         }          }
         my $js = '<script type"text/javascript">'."\n$jscript\n$catjs\n".          $js = '<script type"text/javascript">'."\n$jscript\n$catjs\n".
                  '</script>';                '</script>';
         my %add_entries = (topmargin    => "0",  
                            marginheight => "0",);  
         if (($env{'form.state'} eq 'listing') && ($numtitles > 0)) {          if (($env{'form.state'} eq 'listing') && ($numtitles > 0)) {
             $add_entries{'onLoad'} = 'setElements()';              $add_entries{'onLoad'} = 'setElements()';
         }          }
         &cat_header($r,$codedom,$js,\%add_entries,$catlinks,$numtitles);          &cat_header($r,$codedom,$js,\%add_entries,$catlinks,$numtitles);
         my $cat_maxdepth = $env{'form.catalog_maxdepth'};          my $cat_maxdepth = $env{'form.catalog_maxdepth'};
         $r->print('<form name="'.$formname.'" method="post" action="/adm/coursecatalog">'.          $r->print('<form name="'.$formname.'" method="post" action="/adm/coursecatalog">'.
                   '<input type="hidden" name="catalog_maxdepth" value="'.$cat_maxdepth.'" />'.                    '<input type="hidden" name="catalog_maxdepth" value="'.$cat_maxdepth.'" />'."\n".
                   '<input type="hidden" name="showdom" value="'.$env{'form.showdom'}.'" />'.                    '<input type="hidden" name="showdom" value="'.$env{'form.showdom'}.'" />'."\n".
                   '<input type="hidden" name="currcat_0" value="instcode::0" />');                    '<input type="hidden" name="currcat_0" value="instcode::0" />'.
                     &additional_filters($codedom));
         if ($numtitles > 0) {          if ($numtitles > 0) {
             $r->print('<br /><b>'.&mt('Choose which course(s) to list.').'</b><br />');              $r->print('<b>'.&mt('Choose which course(s) to list.').'</b><br />');
             $r->print('<table><tr>');              $r->print('<table><tr>');
             for (my $k=0; $k<$lasttitle-1; $k++) {              for (my $k=0; $k<$lasttitle-1; $k++) {
                 my (@items,@unsorted);                  my (@items,@unsorted);
Line 266  function setCourseId(caller) { Line 286  function setCourseId(caller) {
                       '<select name="'.$codetitles[$lasttitle-1].'">'."\n".                        '<select name="'.$codetitles[$lasttitle-1].'">'."\n".
                       '<option value="0">All'."\n".                        '<option value="0">All'."\n".
                       '</option>'."\n".'</select>'."\n".                        '</option>'."\n".'</select>'."\n".
                  '</td>'                   '</td></tr></table>'."\n");
                 );  
             my $show_selfenroll_status;  
             if ($env{'form.showselfenroll'}) {  
                 $show_selfenroll_status = 'checked="checked" ';  
             }  
             if (&user_is_dc($codedom)) {  
                 my $showdetails_status;  
                 if ($env{'form.showdetails'}) {  
                     $showdetails_status = 'checked="checked" ';  
                 }  
                 $r->print('<td></td><td><label><input type="checkbox" name="showdetails" value="1" '.$showdetails_status.'/>'.&mt('Show full details for each course (DC only)').'</label><br /><label><input type="checkbox" name="showselfenroll" value="1" '.$show_selfenroll_status.'/>'.&mt('Only show courses which allow self-enrollment').'</label></td>');  
             } else {  
                 $r->print('<td></td><td><br /><label><input type="checkbox" name="showselfenroll" value="1" '.$show_selfenroll_status.'/>'.&mt('Only show courses which allow self-enrollment').'</label></td>');  
             }  
             $r->print('</tr></table>');  
             if ($numtitles > 4) {              if ($numtitles > 4) {
                 $r->print('<br /><br />'.$codetitles[$numtitles-1].'<br />'."\n".                  $r->print('<br /><br />'.$codetitles[$numtitles-1].'<br />'."\n".
                 '<input type="text" name="'.$codetitles[$numtitles-1].'" /><br />'."\n");                  '<input type="text" name="'.$codetitles[$numtitles-1].'" /><br />'."\n");
             }              }
             $r->print('<br />');              $r->print('<br />');
         }          }
         $r->print('<input type="hidden" name="coursenum" value="" /><input type="hidden" name="sortby" value="" /><input type="hidden" name="state" value="listing" /><input type="hidden" name="form.currcat_0" value="instcode::0" />');          $r->print('<input type="hidden" name="coursenum" value="" />'."\n".
         if ($numtitles > 0) {                    '<input type="hidden" name="sortby" value="" />'."\n".
             $r->print('<input type="submit" name="catalogfilter" value="'.&mt('Display courses').'" />');                    '<input type="hidden" name="state" value="listing" />'."\n".
         }                    '<input type="hidden" name="form.currcat_0" value="instcode::0" />'."\n".
         $r->print('<input type="hidden" name="numtitles" value="'.                    '<input type="submit" name="catalogfilter" value="'.
                   $numtitles.'" /></form>');                    &mt('Display courses').'" />'.
                     '<input type="hidden" name="numtitles" value="'.$numtitles.
                     '" /></form>');
         if (($numtitles > 0) && ($env{'form.state'} eq 'listing')) {          if (($numtitles > 0) && ($env{'form.state'} eq 'listing')) {
             $r->print('<br />');              $r->print('<br />');
         }          }
     } else {      } else {
         $r->print('<br />'.&mt('No official courses to display for [_1].',$domdesc));          &cat_header($r,$codedom,$js,\%add_entries,$catlinks,$numtitles);
           my $cat_maxdepth = $env{'form.catalog_maxdepth'};
           $r->print('<form name="'.$formname.'" method="post" action="/adm/coursecatalog">'.
                     '<input type="hidden" name="catalog_maxdepth" value="'.$cat_maxdepth.'" />'.
                     '<input type="hidden" name="showdom" value="'.$env{'form.showdom'}.'" />'.
                     '<input type="hidden" name="currcat_0" value="instcode::0" />');
           $r->print('<br />'.&mt('No official courses to display for [_1].',$domdesc).'</form>');
     }      }
     return $numtitles;      return $numtitles;
 }  }
Line 332  sub cat_header { Line 345  sub cat_header {
               '<form name="coursecatdom" method="post" action="/adm/coursecatalog">'.                '<form name="coursecatdom" method="post" action="/adm/coursecatalog">'.
               '<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="Go"></td></form></tr><tr>'.        '&nbsp;<input type="submit" name="godom" value="'.&mt('Change').'"></td></form></tr>'.
       '<form name="coursecats" method="post" action="/adm/coursecatalog">'.        '<tr><form name="coursecats" method="post" action="/adm/coursecatalog">'.
               $catlinks.'</form></tr></table>');                $catlinks.'</form></tr></table>');
     return;      return;
 }  }
Line 342  sub category_breadcrumbs { Line 355  sub category_breadcrumbs {
     my ($dom) = @_;      my ($dom) = @_;
     my %domconfig =      my %domconfig =
         &Apache::lonnet::get_dom('configuration',['coursecategories'],$dom);          &Apache::lonnet::get_dom('configuration',['coursecategories'],$dom);
     my (@cats,@trails,%allitems,%idx,@jsarray);      my (@cats,@trails,%allitems,%idx,@jsarray,$cathash);
     &Apache::loncommon::extract_categories($domconfig{'coursecategories'},\@cats,\@trails,      if (ref($domconfig{'coursecategories'}) eq 'HASH') {
                                            \%allitems,\%idx,\@jsarray);          $cathash = $domconfig{'coursecategories'}{'cats'};
     my $currdepth = 0;      } else {
     my $deeper = 0;          $cathash = {};
     my $currcat_str;  
     if ($env{'form.catalog_maxdepth'} ne '') {  
         $currdepth = $env{'form.catalog_maxdepth'};  
         $deeper = $currdepth + 1;  
     }      }
     $currcat_str = '<input type="hidden" name="catalog_maxdepth" value="'.$deeper.'" /><input type="hidden" name="showdom" value="'.$dom.'" />';      &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,
                                              \@jsarray);
       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 $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>';
     for (my $i=0; $i<$deeper; $i++) {      for (my $i=0; $i<$deeper; $i++) {
         $currcat_str .= '<input type="hidden" name="currcat_'.$i.'" value="'.$env{'form.currcat_'.$i}.'" />';          $currcat_str .= '<input type="hidden" name="currcat_'.$i.'" value="'.$env{'form.currcat_'.$i}.'" />';
Line 398  sub category_breadcrumbs { Line 410  sub category_breadcrumbs {
                     $catlinks .= '</option>'."\n";                      $catlinks .= '</option>'."\n";
                 }                  }
                 $catlinks .= '</select>'."\n".                  $catlinks .= '</select>'."\n".
                              '&nbsp;<input type="submit" name="gocats" value="Go" />';                               '&nbsp;<input type="submit" name="gocats" value="'.&mt('Change').'" />';
             }              }
         } else {          } else {
             $catlinks .= &mt('Official courses (with institutional codes)').              $catlinks .= &mt('Official courses (with institutional codes)').
Line 406  sub category_breadcrumbs { Line 418  sub category_breadcrumbs {
             $env{'form.currcat_0'} = 'instcode::0';              $env{'form.currcat_0'} = 'instcode::0';
         }          }
     } else {      } else {
         my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$env{'form.currcat_'.$currdepth});          my ($cat,$container,$depth);
           if ($env{'form.currcat_'.$currdepth} eq '') {
               my $shallower = $currdepth - 1;
               ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$env{'form.currcat_'.$shallower});
           } else {
               ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$env{'form.currcat_'.$currdepth});
           }
         my $deeper = $depth +1;          my $deeper = $depth +1;
         my $currcat = $cat;          my $currcat = $cat;
         if ($cat eq 'instcode') {          if ($cat eq 'instcode') {
Line 422  sub category_breadcrumbs { Line 440  sub category_breadcrumbs {
                 $catlinks .= '<option value="'.$item.'">'.$name.'</option>'."\n";                  $catlinks .= '<option value="'.$item.'">'.$name.'</option>'."\n";
             }              }
             $catlinks .= '</select>'."\n".              $catlinks .= '</select>'."\n".
                          '&nbsp;<input type="submit" name="gocats" value="Go" />';                           '&nbsp;<input type="submit" name="gocats" value="'.&mt('Change').'" />';
         }          }
     }      }
     $catlinks .= $currcat_str.'</td></tr></table></td>';      $catlinks .= $currcat_str.'</td></tr></table></td>';
     return $catlinks;      return $catlinks;
 }  }
   
   sub get_depth_values {
       my $currdepth = 0;
       my $deeper = 0;
       if ($env{'form.catalog_maxdepth'} ne '') {
           $currdepth = $env{'form.catalog_maxdepth'};
           if ($env{'form.currcat_'.$currdepth} eq '') {
               $deeper = $currdepth;
           } else {
               $deeper = $currdepth + 1;
           }
       }
       return ($currdepth,$deeper);
   }
   
   sub additional_filters {
       my ($codedom) = @_;
       my $output = '<table>';
       my $show_selfenroll_status;
       if ($env{'form.showselfenroll'}) {
           $show_selfenroll_status = 'checked="checked" ';
       }
       if (&user_is_dc($codedom)) {
           my $showdetails_status;
           if ($env{'form.showdetails'}) {
               $showdetails_status = 'checked="checked" ';
           }
           my $showhidden_status;
           if ($env{'form.showhidden'}) {
                $showhidden_status = 'checked="checked" ';
           }
           my $dc_title = &Apache::lonnet::plaintext('dc');
           $output .= '<tr><td>'."\n".
                      '<label><input type="checkbox" name="showdetails" value="1" '.
                      $showdetails_status.'/>'."\n".
                      &mt('Show full details for each course ([_1] only)',$dc_title).
                      '</label>'."\n".'</td></tr><tr><td>'.
                      '<label><input type="checkbox" name="showhidden" value="1" '.
                      $showhidden_status.'/>'.
                      &mt('Include courses set to be hidden from catalog ([_1] only)',$dc_title).
                      '</label>'."\n".'</td></tr>';
       }
       $output .= '<tr><td>'.
                  '<label><input type="checkbox" name="showselfenroll" value="1" '.
                  $show_selfenroll_status.'/>'.
                  &mt('Only show courses which allow self-enrollment').
                  '</label></td></tr></table><br />';
       return $output;
   }
   
 sub user_is_dc {  sub user_is_dc {
     my ($codedom) = @_;      my ($codedom) = @_;
     if (exists($env{'user.role.dc./'.$codedom.'/'})) {      if (exists($env{'user.role.dc./'.$codedom.'/'})) {
Line 549  sub search_official_courselist { Line 616  sub search_official_courselist {
             $instcode = '.';              $instcode = '.';
         }          }
     }      }
     my %courses = &Apache::lonnet::courseiddump($domain,'.',1,$instcode,'.','.',      my $showhidden;
                                                 undef,undef,'Course',1,      if (&user_is_dc($domain)) {
                                                 $env{'form.showselfenroll'});          $showhidden = $env{'form.showhidden'};
       }
       my %courses = 
           &Apache::lonnet::courseiddump($domain,'.',1,$instcode,'.','.',undef,undef,
                                         'Course',1,$env{'form.showselfenroll'},undef,
                                         $showhidden,'coursecatalog');
     return %courses;      return %courses;
 }  }
   
Line 559  sub search_courselist { Line 631  sub search_courselist {
     my ($domain) = @_;      my ($domain) = @_;
     my $cat_maxdepth = $env{'form.catalog_maxdepth'};      my $cat_maxdepth = $env{'form.catalog_maxdepth'};
     my $filter = $env{'form.currcat_'.$cat_maxdepth};      my $filter = $env{'form.currcat_'.$cat_maxdepth};
       if (($filter eq '') && ($cat_maxdepth > 0)) {
           my $shallower = $cat_maxdepth - 1;
           $filter = $env{'form.currcat_'.$shallower};
       }
     my %courses;      my %courses;
     if ($filter ne '') {      if ($filter ne '') {
         %courses = &Apache::lonnet::courseiddump($domain,'.',1,'.','.','.',          my $showhidden;
                                                  undef,undef,'Course',1,          if (&user_is_dc($domain)) {
                                                  $env{'form.showselfenroll'},$filter);              $showhidden = $env{'form.showhidden'};
           }
           %courses = 
               &Apache::lonnet::courseiddump($domain,'.',1,'.','.','.',undef,undef,
                                             '.',1,$env{'form.showselfenroll'},
                                             $filter,$showhidden,'coursecatalog');
     }      }
     return %courses;      return %courses;
 }  }
Line 582  sub print_course_listing { Line 663  sub print_course_listing {
     if ($env{'form.coursenum'} ne '') {      if ($env{'form.coursenum'} ne '') {
         %courses = &Apache::lonnet::courseiddump($domain,'.',1,'.','.',          %courses = &Apache::lonnet::courseiddump($domain,'.',1,'.','.',
                                                  $env{'form.coursenum'},                                                   $env{'form.coursenum'},
                                                  undef,undef,'Course',1);                                                   undef,undef,'.',1);
         if (keys(%courses) == 0) {          if (keys(%courses) == 0) {
             $output .= &mt('The courseID provided does not match a course in this domain.');              $output .= &mt('The courseID provided does not match a course in this domain.');
             return $output;              return $output;
Line 597  sub print_course_listing { Line 678  sub print_course_listing {
             $output = &mt('No courses match the criteria you selected.');              $output = &mt('No courses match the criteria you selected.');
             return $output;              return $output;
         }          }
         if ($knownuser && !$env{'form.showdetails'}) {          if (($knownuser) && (!$env{'form.showdetails'}) && (!&user_is_dc($domain))) {
             $output = &mt('<b>Note for students:</b> If you are officially enrolled in a course but the course is not listed in your LON-CAPA courses, click the "Show more details" link for the specific course and check the default access dates and/or automated enrollment settings.<br /><br />');              $output = '<b>'.&mt('Note for students:').'</b> '
                        .&mt('If you are officially enrolled in a course but the course is not listed in your LON-CAPA courses, click the "Show more details" link for the specific course and check the default access dates and/or automated enrollment settings.')
                        .'<br /><br />';
         }          }
     }      }
     my $now = time;      my $now = time;

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


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