Annotation of loncom/interface/coursecatalog.pm, revision 1.1
1.1 ! raeburn 1: #
! 2: # Copyright Michigan State University Board of Trustees
! 3: #
! 4: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
! 5: #
! 6: # LON-CAPA is free software; you can redistribute it and/or modify
! 7: # it under the terms of the GNU General Public License as published by
! 8: # the Free Software Foundation; either version 2 of the License, or
! 9: # (at your option) any later version.
! 10: #
! 11: # LON-CAPA is distributed in the hope that it will be useful,
! 12: # but WITHOUT ANY WARRANTY; without even the implied warranty of
! 13: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! 14: # GNU General Public License for more details.
! 15: #
! 16: # You should have received a copy of the GNU General Public License
! 17: # along with LON-CAPA; if not, write to the Free Software
! 18: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
! 19: #
! 20: # /home/httpd/html/adm/gpl.txt
! 21: #
! 22: # http://www.lon-capa.org/
! 23: #
! 24:
! 25: package Apache::coursecatalog;
! 26:
! 27: use strict;
! 28: use lib qw(/home/httpd/lib/perl);
! 29: use Apache::Constants qw(:common);
! 30: use Apache::loncommon;
! 31: use Apache::lonnet;
! 32: use Apache::lonlocal;
! 33: use Apache::lonsupportreq;
! 34: use Apache::lonacc;
! 35: use lib '/home/httpd/lib/perl/';
! 36: use LONCAPA;
! 37:
! 38: sub handler {
! 39: my ($r) = @_;
! 40: &Apache::loncommon::content_type($r,'text/html');
! 41: $r->send_http_header;
! 42: if ($r->header_only) {
! 43: return OK;
! 44: }
! 45: &Apache::lonacc::get_posted_cgi($r);
! 46: &Apache::lonlocal::get_language_handle($r);
! 47: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['sortby']);
! 48: my $codedom = $Apache::lonnet::perlvar{'lonDefDomain'};
! 49: my $ccode = '';
! 50: my %coursecodes = ();
! 51: my %codes = ();
! 52: my @codetitles = ();
! 53: my %cat_titles = ();
! 54: my %cat_order = ();
! 55: my %idlist = ();
! 56: my %idnums = ();
! 57: my %idlist_titles = ();
! 58: my $caller = 'global';
! 59: my $format_reply;
! 60: my $totcodes = 0;
! 61: my $jscript = '';
! 62: my $formname = 'coursecatalog';
! 63: $totcodes = &Apache::lonsupportreq::retrieve_instcodes(\%coursecodes,$codedom,$totcodes);
! 64: if ($totcodes > 0) {
! 65: if ($ccode eq '') {
! 66: $format_reply = &Apache::lonnet::auto_instcode_format($caller,$codedom,\%coursecodes,\%codes,\@codetitles,\%cat_titles,\%cat_order);
! 67: if ($format_reply eq 'ok') {
! 68: my $numtypes = @codetitles;
! 69: &Apache::lonsupportreq::build_code_selections(\%codes,\@codetitles,\%cat_titles,\%cat_order,\%idlist,\%idnums,\%idlist_titles);
! 70: &Apache::lonsupportreq::javascript_code_selections($formname,$numtypes,\%cat_titles,\$jscript,\%idlist,\%idnums,\%idlist_titles,\@codetitles);
! 71: }
! 72: }
! 73: if ($env{'form.state'} eq 'listing') {
! 74: $jscript .= '
! 75: function setElements() {
! 76: ';
! 77: for (my $i=0; $i<@codetitles; $i++) {
! 78: if ($env{'form.'.$codetitles[$i]} != -1) {
! 79: $jscript .= '
! 80: for (var j=0; j<document.'.$formname.'.'.$codetitles[$i].'.length; j++) {
! 81: if (document.'.$formname.'.'.$codetitles[$i].'[j].value == "'.$env{'form.'.$codetitles[$i]}.'") {
! 82: document.'.$formname.'.'.$codetitles[$i].'.selectedIndex = j;
! 83: }
! 84: }
! 85: ';
! 86: $jscript .= ' courseSet('."'$codetitles[$i]'".');'."\n";
! 87: } else {
! 88: last;
! 89: }
! 90: }
! 91: $jscript .= '}';
! 92: $jscript .= qq|
! 93: function changeSort(caller) {
! 94: document.coursecatalog.sortby.value = caller;
! 95: document.coursecatalog.submit();
! 96: }\n|;
! 97: }
! 98: my $js = '<script type"text/javascript">'."\n$jscript\n".
! 99: '</script>';
! 100: my %add_entries = (topmargin => "0",
! 101: marginheight => "0",
! 102: onLoad =>"setElements()",);
! 103: my $start_page =
! 104: &Apache::loncommon::start_page('Course Catalog',$js,
! 105: {
! 106: 'add_entries' => \%add_entries,
! 107: 'no_inline_link' => 1,});
! 108: $r->print($start_page);
! 109:
! 110: my $numtitles = @codetitles;
! 111: my $domdesc = $Apache::lonnet::domaindescription{$codedom};
! 112: $r->print('<h3>'.&mt('Display information about official [_1] courses in LON-CAPA:',$domdesc).'</h3>');
! 113: $r->print(&mt('<b>Choose which course(s) to list.</b><br />'));
! 114: $r->print('<form name="coursecatalog" method="post">');
! 115: if ($numtitles > 0) {
! 116: my $lasttitle = $numtitles;
! 117: if ($numtitles > 4) {
! 118: $lasttitle = 4;
! 119: }
! 120: $r->print('<table><tr><td>'.$codetitles[0].'<br />'."\n".
! 121: '<select name="'.$codetitles[0].'" onChange="courseSet('."'$codetitles[0]'".')">'."\n".
! 122: ' <option value="-1" />Select'."\n");
! 123: my @items = ();
! 124: my @longitems = ();
! 125: if ($idlist{$codetitles[0]} =~ /","/) {
! 126: @items = split/","/,$idlist{$codetitles[0]};
! 127: } else {
! 128: $items[0] = $idlist{$codetitles[0]};
! 129: }
! 130: if (defined($idlist_titles{$codetitles[0]})) {
! 131: if ($idlist_titles{$codetitles[0]} =~ /","/) {
! 132: @longitems = split/","/,$idlist_titles{$codetitles[0]};
! 133: } else {
! 134: $longitems[0] = $idlist_titles{$codetitles[0]};
! 135: }
! 136: for (my $i=0; $i<@longitems; $i++) {
! 137: if ($longitems[$i] eq '') {
! 138: $longitems[$i] = $items[$i];
! 139: }
! 140: }
! 141: } else {
! 142: @longitems = @items;
! 143: }
! 144: for (my $i=0; $i<@items; $i++) {
! 145: $r->print(' <option value="'.$items[$i].'">'.$longitems[$i].'</option>');
! 146: }
! 147: $r->print('</select></td>');
! 148: for (my $i=1; $i<$numtitles; $i++) {
! 149: $r->print('<td>'.$codetitles[$i].'<br />'."\n".
! 150: '<select name="'.$codetitles[$i].'" onChange="courseSet('."'$codetitles[$i]'".')">'."\n".
! 151: '<option value="-1"><-Pick '.$codetitles[$i-1].'</option>'."\n".
! 152: '</select>'."\n".
! 153: '</td>'
! 154: );
! 155: }
! 156: $r->print('</tr></table>');
! 157: if ($numtitles > 4) {
! 158: $r->print('<br /><br />'.$codetitles[$numtitles].'<br />'."\n".
! 159: '<select name="'.$codetitles[$numtitles].
! 160: '" onChange="courseSet('."'$codetitles[$numtitles]'".')">'."\n".
! 161: '<option value="-1"><-Pick '.$codetitles[$numtitles-1].
! 162: '</option>'."\n".'</select>'."\n");
! 163: }
! 164: }
! 165: $r->print('<br /><input type="hidden" name="state" value="listing" /><input type="hidden" name="sortby" value="" /><input type="submit" name="catalogfilter" value="'.&mt('Display courses').'" /></form>');
! 166: }
! 167: if ($env{'form.state'} eq 'listing') {
! 168: $r->print('<br /><br >'.&print_course_listing($codedom));
! 169: }
! 170: $r->print(&Apache::loncommon::end_page());
! 171: }
! 172:
! 173: sub print_course_listing {
! 174: my ($domain) = @_;
! 175: my $output;
! 176: my $year = $env{'form.Year'};
! 177: my $sem = $env{'form.Semester'};
! 178: my $dept = $env{'form.Department'};
! 179: my $coursenum = $env{'form.Number'};
! 180: my $instcode;
! 181: if ($sem != -1) {
! 182: $instcode .= $sem;
! 183: }
! 184: if ($year != -1) {
! 185: $instcode .= $year;
! 186: }
! 187: if ($dept != -1) {
! 188: $instcode .= $dept;
! 189: }
! 190: if ($coursenum != -1) {
! 191: $instcode .= $coursenum;
! 192: }
! 193: my %courses = &Apache::lonnet::courseiddump($domain,'.',1,$instcode,'.','.',
! 194: undef,undef,'Course');
! 195: if (keys(%courses) == 0) {
! 196: $output = &mt('No courses match the criteria you selected');
! 197: return $output;
! 198: }
! 199: $output = &mt('<b>Note for students:</b> If STUINFO shows you as enrolled in a course, but there is no student role for the course in your LON-CAPA roles screen, please check the default access dates and/or auto-enrollment dates for the course listed below. Your roles screen will only display currently accessible roles.<br /><br />');
! 200: $output .= &Apache::loncommon::start_data_table().
! 201: &Apache::loncommon::start_data_table_header_row().
! 202: '<th><a href="javascript:changeSort('."'code'".')">'.&mt('Code').'</a></th>'.
! 203: '<th>'.&mt('Sections').'</th>'.
! 204: '<th><a href="javascript:changeSort('."'title'".')">'.&mt('Title').'</a></th>'.
! 205: '<th><a href="javascript:changeSort('."'owner'".')">'.&mt('Owner').'</a></th>'.
! 206: '<th>'.&mt('Students').'</th>'.
! 207: '<th>'.&mt('Default Access Dates').'</th>'.
! 208: '<th>'.&mt('Auto-enrollment Dates').'</th>'.
! 209: &Apache::loncommon::end_data_table_header_row();
! 210: my %courseinfo;
! 211: foreach my $course (keys(%courses)) {
! 212: my $descr;
! 213: if ($courses{$course} =~ m/^([^:]*):/i) {
! 214: $descr = &unescape($1);
! 215: } else {
! 216: $descr = &unescape($courses{$course});
! 217: }
! 218: my $cleandesc=&HTML::Entities::encode($descr,'<>&"');
! 219: $cleandesc=~s/'/\\'/g;
! 220: my ($cdom,$cnum)=split(/\_/,$course);
! 221: my ($desc,$instcode,$owner,$ttype) = split/:/,$courses{$course};
! 222: $owner = &unescape($owner);
! 223: my ($ownername,$ownerdom);
! 224: if ($owner =~ /:/) {
! 225: ($ownername,$ownerdom) = split(/:/,$owner);
! 226: } else {
! 227: $ownername = $owner;
! 228: if ($owner ne '') {
! 229: $ownerdom = $cdom;
! 230: }
! 231: }
! 232: my %ownernames;
! 233: if ($ownername ne '' && $ownerdom ne '') {
! 234: %ownernames = &Apache::loncommon::getnames($ownername,$ownerdom);
! 235: }
! 236: $courseinfo{$course}{'cdom'} = $cdom;
! 237: $courseinfo{$course}{'cnum'} = $cnum;
! 238: $courseinfo{$course}{'code'} = $instcode;
! 239: $courseinfo{$course}{'ownerlastname'} = $ownernames{'lastname'};
! 240: $courseinfo{$course}{'title'} = $cleandesc;
! 241: }
! 242: my %Sortby;
! 243: foreach my $course (sort(keys(%courses))) {
! 244: if ($env{'form.sortby'} eq 'code') {
! 245: push(@{$Sortby{$courseinfo{$course}{'code'}}},$course);
! 246: } elsif ($env{'form.sortby'} eq 'owner') {
! 247: push(@{$Sortby{$courseinfo{$course}{'ownerlastname'}}},$course);
! 248: } else {
! 249: push(@{$Sortby{$courseinfo{$course}{'title'}}},$course);
! 250: }
! 251: }
! 252: my @sorted_courses;
! 253: if (($env{'form.sortby'} eq 'code') || ($env{'form.sortby'} eq 'owner')) {
! 254: @sorted_courses = sort(keys(%Sortby));
! 255: } else {
! 256: @sorted_courses = sort { lc($a) cmp lc($b) } (keys(%Sortby));
! 257: }
! 258: foreach my $item (@sorted_courses) {
! 259: foreach my $course (@{$Sortby{$item}}) {
! 260: $output.=&Apache::loncommon::start_data_table_row();
! 261: $output.=&courseinfo_row($courseinfo{$course});
! 262: $output.=&Apache::loncommon::end_data_table_row();
! 263: }
! 264: }
! 265: $output .= &Apache::loncommon::end_data_table();
! 266: return $output;
! 267: }
! 268:
! 269: sub courseinfo_row {
! 270: my ($info) = @_;
! 271: my ($cdom,$cnum,$title,$owner,$output);
! 272: if (ref($info) eq 'HASH') {
! 273: $cdom = $info->{'cdom'};
! 274: $cnum = $info->{'cnum'};
! 275: $title = $info->{'title'};
! 276: $owner = $info->{'ownerlastname'};
! 277: } else {
! 278: $output = '<td colspan="7">'.&mt('No information available').'</td>';
! 279: return $output;
! 280: }
! 281: my %coursehash = &Apache::lonnet::dump('environment',$cdom,$cnum);
! 282: my $classlist = &Apache::loncoursedata::get_classlist($cdom,$cnum);
! 283: my %idx;
! 284: $idx{'status'} = &Apache::loncoursedata::CL_STATUS();
! 285: my %status_title = &Apache::lonlocal::texthash (
! 286: Expired => 'Previous access',
! 287: Active => 'Current access',
! 288: Future => 'Future access',
! 289: );
! 290: my %student_count = (
! 291: Expired => 0,
! 292: Active => 0,
! 293: Future => 0,
! 294: );
! 295: while (my ($student,$data) = each %$classlist) {
! 296: $student_count{$data->[$idx{'status'}]} ++;
! 297: }
! 298: my $seclist = &identify_sections($coursehash{'internal.sectionnums'});
! 299: my $countslist;
! 300: my $startaccess = '';
! 301: my $endaccess = '';
! 302: my ($accessdates,$autoenrolldates);
! 303: if ( defined($coursehash{'default_enrollment_start_date'}) ) {
! 304: $startaccess = &Apache::lonlocal::locallocaltime($coursehash{'default_enrollment_start_date'});
! 305: }
! 306: if ( defined($coursehash{'default_enrollment_end_date'}) ) {
! 307: $endaccess = &Apache::lonlocal::locallocaltime($coursehash{'default_enrollment_end_date'});
! 308: if ($coursehash{'default_enrollment_end_date'} == 0) {
! 309: $endaccess = "No ending date";
! 310: }
! 311: }
! 312: if ($startaccess) {
! 313: $accessdates .= &mt('From: ').$startaccess.'<br />';
! 314: }
! 315: if ($endaccess) {
! 316: $accessdates .= &mt('To: ').$endaccess.'<br />';
! 317: }
! 318: if (!defined($coursehash{'internal.autoadds'}) || $coursehash{'internal.autoadds'} == 0) {
! 319: $autoenrolldates = &mt('Not enabled');
! 320: } else {
! 321: my ($autostart,$autoend);
! 322: if ( defined($coursehash{'internal.autostart'}) ) {
! 323: $autostart = &Apache::lonlocal::locallocaltime($coursehash{'internal.autostart'});
! 324: }
! 325: if ( defined($coursehash{'internal.autoend'}) ) {
! 326: $autoend = &Apache::lonlocal::locallocaltime($coursehash{'internal.autoend'});
! 327: if ($coursehash{'internal.autoend'} == 0) {
! 328: $autoend = "No ending date";
! 329: }
! 330: }
! 331: if ($autostart) {
! 332: $autoenrolldates .= &mt('Starts: ').$startaccess.'<br />';
! 333: }
! 334: if ($autoend) {
! 335: $autoenrolldates .= &mt('Ends: ').$endaccess.'<br />';
! 336: }
! 337: if ($autoenrolldates eq '') {
! 338: $autoenrolldates = &mt('No start or end date set');
! 339: }
! 340: }
! 341: foreach my $status ('Active','Future','Expired') {
! 342: $countslist .= '<nobr>'.$status_title{$status}.': '.
! 343: $student_count{$status}.'</nobr><br />';
! 344: }
! 345: $output = '<td>'.$coursehash{'internal.coursecode'}.'</td>'.
! 346: '<td>'.$seclist.'</td>'.
! 347: '<td>'.$title.' <font size="-2">'.
! 348: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$cnum,$cdom).
! 349: '</font></td>'.
! 350: '<td>'.$owner.'</td>'.
! 351: '<td>'.$countslist.'</td>'.
! 352: '<td>'.$accessdates.'</td>'.
! 353: '<td>'.$autoenrolldates.'</td>';
! 354: return $output;
! 355: }
! 356:
! 357: sub identify_sections {
! 358: my ($seclist) = @_;
! 359: my @secnums;
! 360: if ($seclist =~ /,/) {
! 361: my @sections = split/,/,$seclist;
! 362: foreach my $sec (@sections) {
! 363: $sec =~ s/:[^:]*$//;
! 364: push(@secnums,$sec);
! 365: }
! 366: } else {
! 367: if ($seclist =~ m/^([^:]+):/) {
! 368: my $sec = $1;
! 369: if (!grep/^$sec$/,@secnums) {
! 370: push (@secnums,$sec);
! 371: }
! 372: }
! 373: }
! 374: @secnums = sort {$a <=> $b} @secnums;
! 375: my $seclist = join(', ',@secnums);
! 376: return $seclist;
! 377: }
! 378:
! 379:
! 380: 1;
! 381:
! 382:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>