Annotation of loncom/interface/coursecatalog.pm, revision 1.96
1.17 albertel 1: # The LearningOnline Network with CAPA
2: # Handler for displaying the course catalog interface
3: #
1.96 ! raeburn 4: # $Id: coursecatalog.pm,v 1.95 2018/02/01 04:51:02 raeburn Exp $
1.1 raeburn 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
29: package Apache::coursecatalog;
30:
31: use strict;
32: use lib qw(/home/httpd/lib/perl);
33: use Apache::Constants qw(:common);
34: use Apache::loncommon;
1.7 raeburn 35: use Apache::lonhtmlcommon;
1.1 raeburn 36: use Apache::lonnet;
37: use Apache::lonlocal;
1.6 raeburn 38: use Apache::courseclassifier;
1.1 raeburn 39: use Apache::lonacc;
40: use LONCAPA;
1.86 raeburn 41: use LONCAPA::lonauthcgi;
1.1 raeburn 42:
43: sub handler {
44: my ($r) = @_;
45: &Apache::loncommon::content_type($r,'text/html');
46: $r->send_http_header;
47: if ($r->header_only) {
48: return OK;
49: }
1.21 albertel 50: my $handle = &Apache::lonnet::check_for_valid_session($r);
1.8 raeburn 51: my $lonidsdir=$r->dir_config('lonIDsDir');
1.21 albertel 52: if ($handle ne '') {
1.8 raeburn 53: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
54: }
1.1 raeburn 55: &Apache::lonacc::get_posted_cgi($r);
56: &Apache::lonlocal::get_language_handle($r);
1.38 raeburn 57: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
58: ['sortby','showdom']);
1.28 raeburn 59:
1.93 raeburn 60: my $serverdefdom = &Apache::lonnet::default_login_domain();
61: my $codedom = $serverdefdom;
1.19 raeburn 62:
63: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne 'public')) {
64: $codedom = $env{'user.domain'};
65: if ($env{'request.role.domain'} ne '') {
66: $codedom = $env{'request.role.domain'};
67: }
68: }
1.7 raeburn 69: my $formname = 'coursecatalog';
1.28 raeburn 70: if ($env{'form.showdom'} ne '') {
1.75 raeburn 71: $env{'form.showdom'} = &LONCAPA::clean_domain($env{'form.showdom'});
1.28 raeburn 72: if (&Apache::lonnet::domain($env{'form.showdom'}) ne '') {
73: $codedom = $env{'form.showdom'};
1.75 raeburn 74: } else {
75: $env{'form.showdom'} = '';
1.28 raeburn 76: }
77: }
1.93 raeburn 78: my $domdesc = &Apache::lonnet::domain($serverdefdom,'description');
1.7 raeburn 79: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.94 raeburn 80:
81: unless (($serverdefdom eq $codedom) ||
82: (&Apache::lonnet::will_trust('catalog',$serverdefdom,$codedom))) {
1.93 raeburn 83: my $serverdomdesc = &Apache::lonnet::domain($serverdefdom,'description');
84: $r->print(&Apache::loncommon::start_page('Course/Community Catalog'));
85: &Apache::lonhtmlcommon::add_breadcrumb
86: ({href=>"/adm/coursecatalog",
87: text=>"Course/Community Catalog"});
88: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course/Community Catalog'));
89: $r->print('<div>'.&mt('Access to catalog LON-CAPA courses/communities unavailable for: "[_1]" on servers run by: "[_2]".',
90: $domdesc,$serverdomdesc).'</div>');
91: $r->print(&Apache::loncommon::end_page());
92: return OK;
93: }
1.35 raeburn 94: my %domconfig =
95: &Apache::lonnet::get_dom('configuration',['coursecategories'],$codedom);
1.82 raeburn 96: my $knownuser = &user_is_known();
1.90 raeburn 97: my $canviewall = &canview_all($knownuser,$codedom);
1.86 raeburn 98:
1.82 raeburn 99: my ($cathash,$cattype);
1.35 raeburn 100: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
101: $cathash = $domconfig{'coursecategories'}{'cats'};
1.86 raeburn 102: if ($knownuser || $canviewall) {
1.82 raeburn 103: $cattype = $domconfig{'coursecategories'}{'auth'};
104: } else {
105: $cattype = $domconfig{'coursecategories'}{'unauth'};
106: }
1.85 raeburn 107: if ($cattype eq '') {
108: $cattype = 'std';
109: }
1.35 raeburn 110: } else {
111: $cathash = {};
1.83 raeburn 112: $cattype = 'std';
1.82 raeburn 113: }
114: if ($cattype eq 'none') {
115: $r->print(&Apache::loncommon::start_page('Course/Community Catalog'));
116: &Apache::lonhtmlcommon::add_breadcrumb
117: ({href=>"/adm/coursecatalog",
118: text=>"Course/Community Catalog"});
119: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course/Community Catalog'));
1.86 raeburn 120: if ($knownuser || $canviewall) {
1.82 raeburn 121: $r->print('<div>'.&mt('No catalog of LON-CAPA courses/communities is provided for: [_1]',$domdesc).'</div>');
122: } else {
123: if ($domconfig{'coursecategories'}{'auth'} eq 'none') {
124: $r->print('<div>'.&mt('No catalog of LON-CAPA courses/communities is provided for: [_1]',$domdesc).'</div>');
125: } else {
126: $r->print('<div>'.&mt('The catalog of LON-CAPA courses/communities provided for: "[_1]" is only available to users who are logged in.',$domdesc).'</div>');
127: }
128: }
129: $r->print(&Apache::loncommon::end_page());
130: return OK;
131: }
132:
133: my $cnum;
134: if ($cattype eq 'codesrch') {
135: my ($uniquecode,$codemsg,$brtext);
136: if ($env{'form.uniquecode'}) {
137: $uniquecode = $env{'form.uniquecode'};
138: $uniquecode =~ s/^\s+|\s+$//g;
139: }
140: my $js = '<script type="text/javascript">'."\n".
141: '// <![CDATA['."\n".
1.92 raeburn 142: &courselink_javascript($r)."\n".
1.82 raeburn 143: '// ]]>'."\n".
144: '</script>'."\n";
145: $r->print(&Apache::loncommon::start_page('Search for a Course/Community',$js));
146: if ($uniquecode =~ /^\w{6}$/) {
147: &Apache::lonhtmlcommon::add_breadcrumb
148: ({href=>"/adm/coursecatalog",
149: text=>"Course/Community Catalog"});
150: $brtext = 'Search Result';
151: } else {
152: $brtext = 'Course/Community Catalog';
153: }
154: &Apache::lonhtmlcommon::add_breadcrumb
155: ({href=>"/adm/coursecatalog",
156: text=>"$brtext"});
157: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course/Community Catalog'));
158: $r->print(&coursesearch($codedom,$domdesc,$uniquecode));
159: if ($uniquecode =~ /^\w{6}$/) {
160: $r->print('<hr />');
161: my $confname = $codedom.'-domainconfig';
162: my %codes = &Apache::lonnet::get('uniquecodes',[$uniquecode],$codedom,$confname);
163: if ($codes{$uniquecode}) {
164: $cnum = $codes{$uniquecode};
165: my %courses = &Apache::lonnet::courseiddump($codedom,'.',1,'.','.',
166: $cnum,undef,undef,'.',1);
167: if (keys(%courses)) {
1.86 raeburn 168: $env{'form.coursenum'} = $cnum;
169: my %courseinfo = &build_courseinfo_hash(\%courses,$knownuser,$codedom,$canviewall);
1.82 raeburn 170: undef($env{'form.coursenum'});
171: if (ref($courseinfo{$codedom.'_'.$cnum}) eq 'HASH') {
172: $r->print(&Apache::lonhtmlcommon::start_pick_box());
173: my @cols = ('title','ownerlastnames','seclist','access');
174: my %lt = &Apache::lonlocal::texthash(
175: title => 'Title',
176: ownerlastnames => 'Owner & Co-owner(s)',
177: seclist => 'Sections',
178: access => 'Default Access Dates for Students',
179: );
180: my @shown;
181: foreach my $item (@cols) {
182: if ($courseinfo{$codedom.'_'.$cnum}{$item}) {
183: push(@shown,$item);
184: }
185: }
186: my $num = 0;
187: foreach my $item (@shown) {
188: $num ++;
189: $r->print(&Apache::lonhtmlcommon::row_title($lt{$item}).
190: $courseinfo{$codedom.'_'.$cnum}{$item});
191: if ($item eq 'title') {
192: if ($courseinfo{$codedom.'_'.$cnum}{'showsyllabus'}) {
1.91 raeburn 193: my $usehttp = 0;
194: if (($ENV{'SERVER_PORT'} == 443) && ($courseinfo{$codedom.'_'.$cnum}{'extsyllplain'})) {
195: $usehttp = 1;
196: }
1.82 raeburn 197: $r->print(' <font size="-2">'.
1.91 raeburn 198: '<a href="javascript:ToSyllabus('."'$codedom','$cnum','$usehttp'".')">'.
1.82 raeburn 199: &mt('Syllabus').'</a></font>');
200: }
201: }
202: my $arg = ( $num == scalar(@shown) ? 1 : '' );
203: $r->print(&Apache::lonhtmlcommon::row_closure($arg));
204: }
205: $r->print(&Apache::lonhtmlcommon::end_pick_box());
206: my $selfenroll = &selfenroll_status($courseinfo{$codedom.'_'.$cnum},$codedom.'_'.$cnum);
207: if ($selfenroll) {
208: $r->print('<br />'.$selfenroll);
209: }
210: $r->print('<form name="linklaunch" method="post" action="">'."\n".
211: '<input type="hidden" name="backto" value="coursecatalog" />'."\n".
212: '<input type="hidden" name="courseid" value="" />'."\n".
213: '</form>'."\n");
214:
215: } else {
216: $codemsg = &mt('Code matched, but course ID to which this mapped is invalid.');
217: }
218: } else {
219: $codemsg = &mt('Code matched, but course ID to which this mapped is invalid.');
220: }
221: } else {
222: $codemsg = &mt('No match');
223: }
224: }
225: $r->print('<br />'.&Apache::loncommon::end_page());
226: return OK;
227: } else {
1.96 ! raeburn 228: if ($env{'form.coursenum'} ne '') {
! 229: if ($env{'form.coursenum'} =~ /^$LONCAPA::match_courseid$/) {
! 230: $cnum = $env{'form.coursenum'};
! 231: } else {
! 232: delete($env{'form.coursenum'});
! 233: }
1.82 raeburn 234: }
1.35 raeburn 235: }
1.82 raeburn 236:
1.96 ! raeburn 237: my (@cats,@trails,%allitems,%idx,@jsarray,%subcathash,$subcats,%maxd,
! 238: $toplevelstr,$maxdepthstr);
1.36 raeburn 239: if ($env{'form.withsubcats'}) {
240: $subcats = \%subcathash;
241: }
1.35 raeburn 242: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems,
1.96 ! raeburn 243: \%idx,\@jsarray,$subcats,\%maxd);
! 244: if (ref($cats[0]) eq 'ARRAY') {
! 245: foreach my $item (@{$cats[0]}) {
! 246: $toplevelstr .= "'".&js_escape($item)."::0',";
! 247: $maxdepthstr .= "'$maxd{$item}',";
! 248: }
! 249: $toplevelstr =~ s/,$//;
! 250: $maxdepthstr =~ s/,$//;
! 251: }
! 252: &validate_input(\@cats,\%maxd);
1.63 raeburn 253: my ($numtitles,@codetitles);
1.82 raeburn 254: if (($env{'form.coursenum'} ne '') && ($knownuser)) {
1.63 raeburn 255: &course_details($r,$codedom,$formname,$domdesc,\@trails,\%allitems,\@codetitles);
1.7 raeburn 256: } else {
1.46 raeburn 257: my ($catlinks,$has_subcats,$selitem) = &category_breadcrumbs($codedom,@cats);
1.72 raeburn 258: my $wasacctext = &get_wasactive_text();
1.28 raeburn 259: my $catjs = <<"ENDSCRIPT";
260:
261: function setCatDepth(depth) {
1.96 ! raeburn 262: var depth = parseInt(depth);
! 263: if (depth !== NaN) {
! 264: if (depth > 0) {
! 265: var possmaxd = 0;
! 266: var toplevel = new Array($toplevelstr);
! 267: var maxdepths = new Array($maxdepthstr);
! 268: if (toplevel.length) {
! 269: for (var i=0; i<toplevel.length; i++) {
! 270: var item = unescape(toplevel[i]);
! 271: if (item == document.coursecats.currcat_0.value) {
! 272: possmaxd = maxdepths[i];
! 273: break;
! 274: }
! 275: }
! 276: }
! 277: if (depth > possmaxd) {
! 278: depth = possmaxd;
! 279: }
! 280: }
! 281: document.coursecats.catalog_maxdepth.value = depth;
! 282: } else {
! 283: document.coursecats.currcat_0.value = '';
! 284: document.coursecats.catalog_maxdepth.value = '';
1.36 raeburn 285: }
1.28 raeburn 286: document.coursecats.submit();
287: return;
288: }
289:
1.33 raeburn 290: function changeSort(caller) {
291: document.$formname.sortby.value = caller;
292: document.$formname.submit();
293: }
1.40 raeburn 294:
1.33 raeburn 295: function setCourseId(caller) {
296: document.$formname.coursenum.value = caller;
297: document.$formname.submit();
1.37 raeburn 298: }
299:
300: ENDSCRIPT
1.92 raeburn 301: $catjs .= &courselink_javascript($r);
1.86 raeburn 302: if (&user_is_dc($codedom) || $canviewall) {
1.72 raeburn 303: $catjs .= <<ENDTOGGJS
304:
305: function toggleStatuses() {
306: if (document.$formname.showdetails.checked) {
307: document.getElementById('statuschoice').style.display='block';
308: document.getElementById('statuscell').style.borderLeft='1px solid';
309: } else {
310: document.getElementById('statuschoice').style.display='none';
311: document.getElementById('statuscell').style.borderLeft='0px';
312: }
313: return;
314: }
315:
316: function toggleWasActive() {
317: if (document.getElementById('counts_Previous')) {
318: if (document.getElementById('counts_Previous').checked) {
319: document.getElementById('choosewasactive').style.display='block';
320: document.getElementById('choosewasacctext').innerHTML = '$wasacctext';
321: } else {
322: document.getElementById('choosewasactive').style.display='none';
323: document.getElementById('choosewasacctext').innerHTML = '';
324: }
325: }
326: return;
327: }
328:
329: ENDTOGGJS
330: }
1.28 raeburn 331: if ($env{'form.currcat_0'} eq 'instcode::0') {
332: $numtitles = &instcode_course_selector($r,$codedom,$formname,$domdesc,
1.86 raeburn 333: $catlinks,$catjs,\@codetitles,$cattype,$canviewall);
1.28 raeburn 334: if ($env{'form.state'} eq 'listing') {
1.63 raeburn 335: $r->print(&print_course_listing($codedom,$numtitles,undef,undef,undef,
1.86 raeburn 336: \@codetitles,$canviewall));
1.28 raeburn 337: }
338: } else {
339: my (%add_entries);
1.50 raeburn 340: my ($currdepth,$deeper) = &get_depth_values();
1.46 raeburn 341: if ($selitem) {
1.50 raeburn 342: my $alert = &mt('Choose a subcategory to display');
343: if (!$deeper) {
344: $alert = &mt('Choose a category to display');
345: }
1.88 damieng 346: &js_escape(\$alert);
1.46 raeburn 347: $catjs .= <<ENDJS;
348: function check_selected() {
349: if (document.coursecats.$selitem.options[document.coursecats.$selitem.selectedIndex].value == "") {
1.50 raeburn 350: alert('$alert');
1.46 raeburn 351: return false;
352: }
353: }
354: ENDJS
355: }
1.28 raeburn 356: $catjs = '<script type="text/javascript">'."\n".$catjs."\n".'</script>';
1.82 raeburn 357: &cat_header($r,$codedom,$catjs,\%add_entries,$catlinks,undef,$cattype);
1.28 raeburn 358: if ($env{'form.currcat_0'} ne '') {
1.33 raeburn 359: $r->print('<form name="'.$formname.
360: '" method="post" action="/adm/coursecatalog">'.
1.86 raeburn 361: &additional_filters($codedom,$has_subcats,$canviewall)."\n");
1.33 raeburn 362: $r->print('<input type="hidden" name="catalog_maxdepth" value="'.
363: $deeper.'" />'."\n");
364: for (my $i=0; $i<$deeper; $i++) {
365: $r->print('<input type="hidden" name="currcat_'.$i.'" value="'.$env{'form.currcat_'.$i}.'" />'."\n");
366: }
1.57 raeburn 367: my $display_button;
368: if ($env{'form.currcat_0'} eq 'communities::0') {
369: $display_button = &mt('Display communities');
1.89 raeburn 370: } elsif ($env{'form.currcat_0'} eq 'placement::0') {
371: $display_button = &mt('Display placement tests');
1.57 raeburn 372: } else {
373: $display_button = &mt('Display courses');
374: }
1.33 raeburn 375: $r->print('<input type="hidden" name="coursenum" value="" />'."\n".
376: '<input type="hidden" name="sortby" value="" />'."\n".
377: '<input type="hidden" name="state" value="listing" />'."\n".
378: '<input type="hidden" name="showdom" value="'.
379: $env{'form.showdom'}.'" />'.
380: '<input type="submit" name="catalogfilter" value="'.
1.57 raeburn 381: $display_button.'" /></form><br /><br />');
1.33 raeburn 382: }
383: if ($env{'form.state'} eq 'listing') {
1.86 raeburn 384: $r->print(&print_course_listing($codedom,undef,\@trails,\%allitems,$subcats,\@codetitles,
385: $canviewall));
1.28 raeburn 386: }
1.18 raeburn 387: }
1.7 raeburn 388: }
1.32 raeburn 389: $r->print('<br />'.&Apache::loncommon::end_page());
1.7 raeburn 390: return OK;
391: }
392:
1.96 ! raeburn 393: sub validate_input {
! 394: my ($cats,$maxd) = @_;
! 395: my $currcat = '';
! 396: my $depth = 0;
! 397: if ($env{'form.catalog_maxdepth'} ne '') {
! 398: $env{'form.catalog_maxdepth'} =~ s{\D}{}g;
! 399: }
! 400: if ((ref($cats) eq 'ARRAY') && (ref($maxd) eq 'HASH')) {
! 401: if (ref($cats->[0]) eq 'ARRAY') {
! 402: if (@{$cats->[0]} == 1) {
! 403: if ($cats->[0][0] eq 'instcode') {
! 404: $currcat = 'instcode::0';
! 405: } elsif ($cats->[0][0] eq 'communities') {
! 406: $currcat = 'communities::0';
! 407: } elsif ($cats->[0][0] eq 'placement') {
! 408: $currcat = 'placement::0';
! 409: } else {
! 410: my $name = $cats->[0][0];
! 411: $currcat = &escape($name).'::0';
! 412: }
! 413: if (exists($maxd->{$cats->[0][0]})) {
! 414: if ($env{'form.catalog_maxdepth'} <= $maxd->{$cats->[0][0]}) {
! 415: $depth = $env{'form.catalog_maxdepth'};
! 416: } else {
! 417: $depth = $maxd->{$cats->[0][0]};
! 418: }
! 419: }
! 420: } elsif ((@{$cats->[0]} > 1) && ($env{'form.currcat_0'} ne '')) {
! 421: my ($escname) = ($env{'form.currcat_0'} =~ /^([^:]+)\:\:0$/);
! 422: if ($escname =~ /^instcode|communities|placement$/) {
! 423: $currcat = $env{'form.currcat_0'};
! 424: if (exists($maxd->{$escname})) {
! 425: if ($env{'form.catalog_maxdepth'} <= $maxd->{$escname}) {
! 426: $depth = $env{'form.catalog_maxdepth'};
! 427: } else {
! 428: $depth = $maxd->{$escname};
! 429: }
! 430: } else {
! 431: $depth = 1;
! 432: }
! 433: } elsif ($escname ne '') {
! 434: my $name = &unescape($escname);
! 435: if (grep(/^\Q$name\E$/,@{$cats->[0]})) {
! 436: $currcat = $env{'form.currcat_0'};
! 437: if (exists($maxd->{$name})) {
! 438: if ($env{'form.catalog_maxdepth'} <= $maxd->{$name}) {
! 439: $depth = $env{'form.catalog_maxdepth'};
! 440: } else {
! 441: $depth = $maxd->{$name};
! 442: }
! 443: }
! 444: }
! 445: }
! 446: }
! 447: }
! 448: }
! 449: $env{'form.currcat_0'} = $currcat;
! 450: $env{'form.catalog_maxdepth'} = $depth;
! 451: return;
! 452: }
! 453:
1.7 raeburn 454: sub course_details {
1.63 raeburn 455: my ($r,$codedom,$formname,$domdesc,$trails,$allitems,$codetitles) = @_;
1.7 raeburn 456: my $output;
457: my %add_entries = (topmargin => "0",
458: marginheight => "0",);
1.40 raeburn 459: my $js = '<script type="text/javascript">'."\n".
1.92 raeburn 460: &courselink_javascript($r).'</script>'."\n";
1.7 raeburn 461: my $start_page =
1.56 bisitz 462: &Apache::loncommon::start_page('Course/Community Catalog',$js,
1.72 raeburn 463: {'add_entries' => \%add_entries, });
1.7 raeburn 464: $r->print($start_page);
1.19 raeburn 465: if ($env{'form.numtitles'} > 0) {
466: &Apache::lonhtmlcommon::add_breadcrumb
467: ({href=>"/adm/coursecatalog",
1.56 bisitz 468: text=>"Course/Community Catalog"});
1.19 raeburn 469: }
1.60 raeburn 470: my $brtextone = 'Course listing';
471: my $brtexttwo = 'Course details';
1.89 raeburn 472: my $textthree = &mt('Detailed course information:');
473: my $textfour = &mt('Back to course listing');
1.60 raeburn 474: if ($env{'form.currcat_0'} eq 'communities::0') {
475: $brtextone = 'Community listing';
1.61 raeburn 476: $brtexttwo = 'Community details';
1.89 raeburn 477: $textthree = &mt('Detailed community information:');
478: $textfour = &mt('Back to community listing');
479: } elsif ($env{'form.currcat_0'} eq 'placement::0') {
480: $brtextone = 'Placement test listing';
481: $brtexttwo = 'Placement test details';
482: $textthree = &mt('Detailed placement test information:');
483: $textfour = &mt('Back to placement test listing');
1.60 raeburn 484: }
1.7 raeburn 485: &Apache::lonhtmlcommon::add_breadcrumb
1.19 raeburn 486: ({href=>"javascript:document.$formname.submit()",
1.60 raeburn 487: text=>$brtextone},
488: {text=>$brtexttwo});
1.78 bisitz 489: $r->print(
490: &Apache::lonhtmlcommon::breadcrumbs('Course/Community Catalog').
1.89 raeburn 491: '<h2>'.$textthree.'</h2>'.
1.78 bisitz 492: &print_course_listing($codedom,undef,$trails,$allitems,undef,$codetitles).
493: '<br />'.
494: '<form name="'.$formname.'" method="post" action="/adm/coursecatalog">'.
495: &Apache::lonhtmlcommon::actionbox([
1.89 raeburn 496: '<a href = "javascript:document.coursecatalog.submit()">'.$textfour.'</a>']).
1.78 bisitz 497: &Apache::lonhtmlcommon::echo_form_input(['coursenum','catalogfilter',
498: 'showdetails','courseid']).
499: '</form>');
1.40 raeburn 500: return;
501: }
502:
1.82 raeburn 503: sub coursesearch {
504: my ($codedom,$domdesc,$uniquecode) = @_;
505: my %lt = &Apache::lonlocal::texthash (
506: crlk => 'Course look-up',
507: code => 'Code',
1.84 raeburn 508: ifyo => 'Enter the course code (six letters and numbers)',
1.82 raeburn 509: srch => 'Find course',
510: );
511: return <<"END";
512: <h3>$lt{'crlk'} ($domdesc)</h3>
513: $lt{'ifyo'}
514: <form name="searchbycode" method="post" action="">
515: <span class="LC_nobreak">
516: <input type="text" value="$uniquecode" size="6" name="uniquecode" />
517: <br />
518: <input type="submit" value="$lt{'srch'}" name="srch" /></span>
519: </form>
520: END
521: }
522:
1.41 raeburn 523: sub courselink_javascript {
1.92 raeburn 524: my ($r) = @_;
525: my $hostname = $r->hostname();
1.40 raeburn 526: return <<"END";
527:
1.91 raeburn 528: function ToSyllabus(cdom,cnum,usehttp) {
1.40 raeburn 529: if (cdom == '' || cdom == null) {
530: return;
531: }
532: if (cnum == '' || cnum == null) {
533: return;
534: }
1.41 raeburn 535: document.linklaunch.action = "/public/"+cdom+"/"+cnum+"/syllabus";
1.91 raeburn 536: if (usehttp == 1) {
1.92 raeburn 537: var hostname = '$hostname';
538: if (hostname != '') {
539: document.linklaunch.action = 'http://'+hostname+document.linklaunch.action;
540: }
1.91 raeburn 541: document.linklaunch.action += '?usehttp=1';
542: }
1.41 raeburn 543: document.linklaunch.submit();
544: }
545:
546: function ToSelfenroll(courseid) {
547: if (courseid == '') {
548: return;
549: }
550: document.linklaunch.action = "/adm/selfenroll";
551: document.linklaunch.courseid.value = courseid;
552: document.linklaunch.submit();
1.40 raeburn 553: }
554:
555: END
1.7 raeburn 556: }
557:
1.28 raeburn 558: sub instcode_course_selector {
1.86 raeburn 559: my ($r,$codedom,$formname,$domdesc,$catlinks,$catjs,$codetitles,$cattype,$canviewall) = @_;
1.1 raeburn 560: my %coursecodes = ();
561: my %codes = ();
562: my %cat_titles = ();
563: my %cat_order = ();
1.6 raeburn 564: my %cat_items;
1.1 raeburn 565: my $caller = 'global';
566: my $format_reply;
1.30 raeburn 567: my %add_entries = (topmargin => "0",
568: marginheight => "0",);
1.51 raeburn 569: my ($jscript,$totcodes,$numtitles,$lasttitle) =
570: &Apache::courseclassifier::instcode_selectors_data($codedom,$formname,
1.63 raeburn 571: \%cat_items,$codetitles,\%cat_titles,\%cat_order);
1.80 bisitz 572: my $js = '<script type="text/javascript">'."\n".
1.79 raeburn 573: '// <![CDATA['."\n".
574: "$jscript\n$catjs\n".
575: '// ]]>'."\n".
576: '</script>';
1.51 raeburn 577: if ($totcodes) {
1.18 raeburn 578: if (($env{'form.state'} eq 'listing') && ($numtitles > 0)) {
1.87 raeburn 579: $add_entries{'onload'} = 'setElements();';
1.72 raeburn 580: }
1.86 raeburn 581: if (&user_is_dc($codedom) || $canviewall) {
1.87 raeburn 582: $add_entries{'onload'} .= ' toggleStatuses();toggleWasActive();'
1.7 raeburn 583: }
1.82 raeburn 584: &cat_header($r,$codedom,$js,\%add_entries,$catlinks,$numtitles,$cattype);
1.28 raeburn 585: my $cat_maxdepth = $env{'form.catalog_maxdepth'};
586: $r->print('<form name="'.$formname.'" method="post" action="/adm/coursecatalog">'.
1.32 raeburn 587: '<input type="hidden" name="catalog_maxdepth" value="'.$cat_maxdepth.'" />'."\n".
588: '<input type="hidden" name="showdom" value="'.$env{'form.showdom'}.'" />'."\n".
589: '<input type="hidden" name="currcat_0" value="instcode::0" />'.
1.86 raeburn 590: &additional_filters($codedom,undef,$canviewall));
1.1 raeburn 591: if ($numtitles > 0) {
1.51 raeburn 592: $r->print('<b>'.&mt('Choose which course(s) to list.').'</b><br />'.
593: &Apache::courseclassifier::build_instcode_selectors($numtitles,
1.63 raeburn 594: $lasttitle,\%cat_items,$codetitles,\%cat_titles,\%cat_order));
1.18 raeburn 595: }
1.33 raeburn 596: $r->print('<input type="hidden" name="coursenum" value="" />'."\n".
597: '<input type="hidden" name="sortby" value="" />'."\n".
598: '<input type="hidden" name="state" value="listing" />'."\n".
599: '<input type="submit" name="catalogfilter" value="'.
600: &mt('Display courses').'" />'.
601: '<input type="hidden" name="numtitles" value="'.$numtitles.
1.37 raeburn 602: '" /></form><br /><br />');
1.5 raeburn 603: } else {
1.81 raeburn 604: $js = '<script type="text/javascript">'."\n".
605: '// <![CDATA['."\n".
606: "$catjs\n".
607: '// ]]>'."\n".
608: '</script>';
1.82 raeburn 609: &cat_header($r,$codedom,$js,\%add_entries,$catlinks,$numtitles,$cattype);
1.30 raeburn 610: my $cat_maxdepth = $env{'form.catalog_maxdepth'};
611: $r->print('<form name="'.$formname.'" method="post" action="/adm/coursecatalog">'.
612: '<input type="hidden" name="catalog_maxdepth" value="'.$cat_maxdepth.'" />'.
613: '<input type="hidden" name="showdom" value="'.$env{'form.showdom'}.'" />'.
614: '<input type="hidden" name="currcat_0" value="instcode::0" />');
615: $r->print('<br />'.&mt('No official courses to display for [_1].',$domdesc).'</form>');
1.1 raeburn 616: }
1.18 raeburn 617: return $numtitles;
1.1 raeburn 618: }
619:
1.28 raeburn 620: sub cat_header {
1.82 raeburn 621: my ($r,$codedom,$js,$add_entries,$catlinks,$numtitles,$cattype) = @_;
1.28 raeburn 622: my $start_page =
1.72 raeburn 623: &Apache::loncommon::start_page('Course/Community Catalog',$js,
1.59 droeschl 624: { 'add_entries' => $add_entries, });
1.28 raeburn 625: $r->print($start_page);
1.60 raeburn 626: my $brtext = 'Course listing';
627: if ($env{'form.currcat_0'} eq 'communities::0') {
628: $brtext = 'Community listing';
1.89 raeburn 629: } elsif ($env{'form.currcat_0'} eq 'placement::0') {
630: $brtext = 'Placement test listing';
1.60 raeburn 631: }
1.28 raeburn 632: if ($env{'form.state'} eq 'listing') {
633: if ($numtitles > 0) {
634: &Apache::lonhtmlcommon::add_breadcrumb
635: ({href=>"/adm/coursecatalog",
1.56 bisitz 636: text=>"Course/Community Catalog"},
1.60 raeburn 637: {text=>$brtext});
1.28 raeburn 638: } else {
639: &Apache::lonhtmlcommon::add_breadcrumb
1.60 raeburn 640: ({text=>$brtext});
1.28 raeburn 641: }
642: } else {
643: &Apache::lonhtmlcommon::add_breadcrumb
644: ({href=>"/adm/coursecatalog",
1.56 bisitz 645: text=>"Course/Community Catalog"});
1.28 raeburn 646: }
1.55 raeburn 647: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course/Community Catalog'));
1.82 raeburn 648: if ($cattype eq 'std') {
649: my $onchange = 'this.form.submit()';
650: $r->print('<form name="coursecatdom" method="post" action="/adm/coursecatalog">'.
651: '<table border="0"><tr><td><b>'.&mt('Domain:').'</b></td><td>'.
652: &Apache::loncommon::select_dom_form($codedom,'showdom','',1,$onchange));
653: if (!$onchange) {
1.47 raeburn 654: $r->print(' <input type="submit" name="godom" value="'.&mt('Change').'" />');
1.82 raeburn 655: }
656: $r->print('</td></tr></table></form>');
1.47 raeburn 657: }
1.82 raeburn 658: $r->print('<form name="coursecats" method="post" action="/adm/coursecatalog"'.
1.48 raeburn 659: ' onsubmit="return check_selected();">'.
1.34 raeburn 660: '<table border="0"><tr>'.$catlinks.'</tr></table></form>');
1.28 raeburn 661: return;
662: }
663:
664: sub category_breadcrumbs {
1.35 raeburn 665: my ($dom,@cats) = @_;
1.44 raeburn 666: my $crumbsymbol = ' ▶ ';
1.33 raeburn 667: my ($currdepth,$deeper) = &get_depth_values();
1.57 raeburn 668: my $currcat_str =
669: '<input type="hidden" name="catalog_maxdepth" value="'.$deeper.'" />'.
670: '<input type="hidden" name="showdom" value="'.$dom.'" />';
1.58 raeburn 671: my $catlinks = '<td valign="top"><b>'.&mt('Catalog:').'</b></td><td><table><tr><td>';
1.36 raeburn 672: my $has_subcats;
1.46 raeburn 673: my $selitem;
1.58 raeburn 674: if (ref($cats[0]) eq 'ARRAY') {
675: if (@{$cats[0]} == 0) {
676: $catlinks .= &mt('No categories defined in this domain');
677: } elsif (@{$cats[0]} == 1) {
678: if ($cats[0][0] eq 'instcode') {
679: $catlinks .= &mt('Official courses (with institutional codes)');
680: $env{'form.currcat_0'} = 'instcode::0';
681: } elsif ($cats[0][0] eq 'communities') {
682: $catlinks .= &mt('Communities');
683: $env{'form.currcat_0'} = 'communities::0';
1.89 raeburn 684: } elsif ($cats[0][0] eq 'placement') {
685: $catlinks .= &mt('Placement Tests');
686: $env{'form.currcat_0'} = 'placement::0';
1.58 raeburn 687: } else {
688: my $name = $cats[0][0];
689: my $item = &escape($name).'::0';
690: $catlinks .= $name;
691: $env{'form.currcat_0'} = $item;
1.46 raeburn 692: }
1.58 raeburn 693: $currcat_str .= '<input type="hidden" name="currcat_0" value="'.$env{'form.currcat_0'}.'" />';
1.28 raeburn 694: } else {
1.58 raeburn 695: $catlinks .= &main_category_selector(@cats);
696: if (($env{'form.currcat_0'} ne '') &&
697: ($env{'form.currcat_0'} ne 'instcode::0')) {
698: $catlinks .= $crumbsymbol;
699: }
700: }
701: } else {
702: $catlinks .= &mt('Official courses (with institutional codes)');
703: $env{'form.currcat_0'} = 'instcode::0';
704: $currcat_str .= '<input type="hidden" name="currcat_0" value="'.$env{'form.currcat_0'}.'" />';
705: }
706: if ($deeper) {
707: for (my $i=1; $i<=$deeper; $i++) {
708: my $shallower = $i-1;
709: next if ($shallower == 0);
1.28 raeburn 710: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$env{'form.currcat_'.$shallower});
1.58 raeburn 711: if ($cat ne '') {
712: $catlinks .= '<td valign="top">'.
713: '<select name="currcat_'.$shallower.'" onchange="'.
714: 'setCatDepth('."'$shallower'".');this.form.submit();">';
715: if (ref($cats[$shallower]{$container}) eq 'ARRAY') {
716: $catlinks .= '<option value="">'.&mt('De-select').'</option>';
717: for (my $j=0; $j<@{$cats[$shallower]{$container}}; $j++) {
718: my $name = $cats[$shallower]{$container}[$j];
1.65 raeburn 719: my $item = &escape($name).':'.&escape($container).':'.$shallower;
1.58 raeburn 720: my $selected = '';
721: if ($item eq $env{'form.currcat_'.$shallower}) {
722: $selected = ' selected="selected"';
723: }
724: $catlinks .=
725: '<option value="'.$item.'"'.$selected.'>'.$name.'</option>';
1.28 raeburn 726: }
727: }
1.58 raeburn 728: $catlinks .= '</select>';
1.28 raeburn 729: }
1.58 raeburn 730: unless ($i == $deeper) {
731: $catlinks .= $crumbsymbol;
732: }
1.28 raeburn 733: }
1.29 raeburn 734: my ($cat,$container,$depth);
735: if ($env{'form.currcat_'.$currdepth} eq '') {
736: my $shallower = $currdepth - 1;
737: ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$env{'form.currcat_'.$shallower});
738: } else {
739: ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$env{'form.currcat_'.$currdepth});
740: }
1.58 raeburn 741: my $deeperlevel = $depth +1;
742: if (ref($cats[$deeperlevel]{$cat}) eq 'ARRAY') {
1.36 raeburn 743: $has_subcats = 1;
1.46 raeburn 744: my $buttontext = &mt('Show subcategories');
1.58 raeburn 745: my $selitem = 'currcat_'.$deeperlevel;
746: $catlinks .= ' <select name="'.$selitem.'" onchange="this.form.submit()">';
747: if (@{$cats[$deeperlevel]{$cat}}) {
1.46 raeburn 748: $catlinks .= '<option value="" selected="selected">'.
1.58 raeburn 749: &mt('Subcategory ...').'</option>';
1.46 raeburn 750: }
1.58 raeburn 751: for (my $k=0; $k<@{$cats[$deeperlevel]{$cat}}; $k++) {
752: my $name = $cats[$deeperlevel]{$cat}[$k];
753: my $item = &escape($name).':'.&escape($cat).':'.$deeperlevel;
1.28 raeburn 754: $catlinks .= '<option value="'.$item.'">'.$name.'</option>'."\n";
755: }
1.58 raeburn 756: $catlinks .= '</select>'."\n";
1.46 raeburn 757: } elsif ($cat ne 'instcode') {
758: $catlinks .= ' '.&mt('(No subcategories)');
1.28 raeburn 759: }
1.58 raeburn 760: } else {
761: $selitem = 'currcat_0';
1.28 raeburn 762: }
763: $catlinks .= $currcat_str.'</td></tr></table></td>';
1.46 raeburn 764: return ($catlinks,$has_subcats,$selitem);
1.28 raeburn 765: }
766:
1.58 raeburn 767: sub main_category_selector {
768: my (@cats) = @_;
769: my $maincatlinks = '<select name="currcat_0" onchange="setCatDepth('."'0'".');this.form.submit();">'."\n";
770: if (ref($cats[0]) eq 'ARRAY') {
771: if (@{$cats[0]} > 1) {
772: my $selected = '';
773: if ($env{'form.currcat_0'} eq '') {
774: $selected = ' selected="selected"';
775: }
776: $maincatlinks .=
777: '<option value=""'.$selected.'>'.&mt('Select').'</option>'."\n";
778: }
779: for (my $i=0; $i<@{$cats[0]}; $i++) {
780: my $name = $cats[0][$i];
781: my $item = &escape($name).'::0';
782: my $selected;
783: if ($env{'form.currcat_0'} eq $item) {
784: $selected = ' selected="selected"';
785: }
786: $maincatlinks .= '<option value="'.$item.'"'.$selected.'>';
787: if ($name eq 'instcode') {
788: $maincatlinks .= &mt('Official courses (with institutional codes)');
789: } elsif ($name eq 'communities') {
790: $maincatlinks .= &mt('Communities');
1.89 raeburn 791: } elsif ($name eq 'placement') {
792: $maincatlinks .= &mt('Placement Tests');
1.58 raeburn 793: } else {
794: $maincatlinks .= $name;
795: }
796: $maincatlinks .= '</option>'."\n";
797: }
798: $maincatlinks .= '</select>'."\n";
799: }
800: return $maincatlinks;
801: }
802:
1.33 raeburn 803: sub get_depth_values {
804: my $currdepth = 0;
805: my $deeper = 0;
806: if ($env{'form.catalog_maxdepth'} ne '') {
807: $currdepth = $env{'form.catalog_maxdepth'};
808: if ($env{'form.currcat_'.$currdepth} eq '') {
809: $deeper = $currdepth;
810: } else {
811: $deeper = $currdepth + 1;
812: }
813: }
814: return ($currdepth,$deeper);
815: }
816:
817: sub additional_filters {
1.86 raeburn 818: my ($codedom,$has_subcats,$canviewall) = @_;
1.72 raeburn 819: my $is_dc = &user_is_dc($codedom);
820: my $output = '<div class="LC_left_float">';
1.86 raeburn 821: if ($is_dc || $canviewall) {
1.72 raeburn 822: $output .= '<fieldset><legend>'.&mt('Options').'</legend>';
823: }
824: $output .= '<table><tr><td valign="top">';
825: if (($env{'form.currcat_0'} ne 'instcode::0') &&
1.36 raeburn 826: ($env{'form.currcat_0'} ne '') && ($has_subcats)) {
827: my $include_subcat_status;
828: if ($env{'form.withsubcats'}) {
829: $include_subcat_status = 'checked="checked" ';
830: }
831: my $counter = $env{'form.catalog_maxdepth'};
832: if ($counter > 0) {
833: if ($env{'form.state'} eq 'listing') {
834: $counter --;
835: } elsif ($env{'form.currcat_'.$counter} eq '') {
836: $counter --;
837: }
838: }
839: my ($catname) = split(/:/,$env{'form.currcat_'.$counter});
840: if ($catname ne '') {
1.72 raeburn 841: $output .= '<span class="LC_nobreak"><label>'.
1.36 raeburn 842: '<input type="checkbox" name="withsubcats" value="1" '.
843: $include_subcat_status.'/>'.
1.38 raeburn 844: &mt('Include subcategories within "[_1]"',
1.72 raeburn 845: &unescape($catname)).'</label></span><br />';
1.36 raeburn 846: }
847: }
1.33 raeburn 848: my $show_selfenroll_status;
849: if ($env{'form.showselfenroll'}) {
850: $show_selfenroll_status = 'checked="checked" ';
851: }
1.57 raeburn 852: my $selfenroll_text;
853: if ($env{'form.currcat_0'} eq 'communities::0') {
1.69 raeburn 854: $selfenroll_text = &mt('Only show communities which currently allow self-enrollment (or will allow it in the future)');
1.89 raeburn 855: } elsif ($env{'form.currcat_0'} eq 'placement::0') {
856: $selfenroll_text = &mt('Only show placement tests which currently allow self-enrollment (or will allow it in the future)');
1.57 raeburn 857: } else {
1.69 raeburn 858: $selfenroll_text = &mt('Only show courses which currently allow self-enrollment (or will allow it in the future)');
1.57 raeburn 859: }
1.72 raeburn 860: $output .= '<span class="LC_nobreak">'.
1.36 raeburn 861: '<label><input type="checkbox" name="showselfenroll" value="1" '.
1.57 raeburn 862: $show_selfenroll_status.'/>'.$selfenroll_text.
1.72 raeburn 863: '</label></span><br />';
1.86 raeburn 864: if ($is_dc || $canviewall) {
1.72 raeburn 865: my ($titlesref,$orderref) = &get_statustitles('filters');
1.33 raeburn 866: my $showdetails_status;
867: if ($env{'form.showdetails'}) {
868: $showdetails_status = 'checked="checked" ';
869: }
870: my $showhidden_status;
871: if ($env{'form.showhidden'}) {
1.72 raeburn 872: $showhidden_status = 'checked="checked" ';
1.33 raeburn 873: }
1.72 raeburn 874: my @currstatuses = &Apache::loncommon::get_env_multiple('form.showcounts');
875: my ($details_text,$hidden_text,$statusdisplay,$cellborder);
876: my $wasactivedisplay = 'none';
877: if ($env{'form.showdetails'}) {
878: $statusdisplay = 'block';
879: $cellborder = 'border-left: 1px solid;';
880: if (grep(/^Previous$/,@currstatuses)) {
881: $wasactivedisplay = 'block';
882: }
883: } else {
884: $statusdisplay = 'none';
885: $cellborder = 'border-left: 0px';
886: }
1.57 raeburn 887: if ($env{'form.currcat_0'} eq 'communities::0') {
1.90 raeburn 888: $details_text = &mt('Show full details for each community (domain staff only)');
889: $hidden_text = &mt('Include communities set to be hidden from catalog (domain staff only)');
1.89 raeburn 890: } elsif ($env{'form.currcat_0'} eq 'placement::0') {
1.90 raeburn 891: $details_text = &mt('Show full details for each placement test (domain staff only)');
892: $hidden_text = &mt('Include placement tests set to be hidden from catalog (domain staff only)');
1.57 raeburn 893: } else {
1.90 raeburn 894: $details_text = &mt('Show full details for each course (domain staff only)');
895: $hidden_text = &mt('Include courses set to be hidden from catalog (domain staff only)');
1.57 raeburn 896: }
1.86 raeburn 897: if ($is_dc) {
898: $output .= '<span class="LC_nobreak">'.
899: '<label><input type="checkbox" name="showhidden" value="1" '.
900: $showhidden_status.'/>'.$hidden_text.
901: '</label></span><br />'."\n";
902: }
1.72 raeburn 903: $output .= '<span class="LC_nobreak">'.
904: '<label><input type="checkbox" name="showdetails" value="1" '.
905: $showdetails_status.'onclick="toggleStatuses();" />'.
906: $details_text.'</label></span></td>'."\n".
907: '<td id="statuscell" valign="top" style="'.$cellborder.'">'.
908: '<div id="statuschoice" style="display:'.$statusdisplay.'">';
909: if (ref($orderref) eq 'ARRAY') {
910: if (@{$orderref} > 0) {
911: foreach my $type (@{$orderref}) {
912: my $checked;
913: if (grep(/^\Q$type\E$/,@currstatuses)) {
914: $checked = ' checked="checked"';
915: }
916: my $title;
917: if (ref($titlesref) eq 'HASH') {
918: $title = $titlesref->{$type};
919: }
920: unless ($title) {
921: $title = &mt($type);
922: }
923: my $onclick;
924: if ($type eq 'Previous') {
925: $onclick = ' onclick="toggleWasActive();"';
926: }
927: $output .= '<span class="LC_nobreak">'.
928: '<label><input type="checkbox" id="counts_'.$type.'"'.
929: ' name="showcounts" value="'.$type.'"'.$checked.$onclick.
930: ' />'.$title.'</label></span>';
931: if ($type eq 'Previous') {
932: my %milestonetext = &Apache::lonlocal::texthash (
1.74 raeburn 933: accessend => 'immediately prior to default end access date',
934: enrollend => 'immediately prior to end date for auto-enrollment',
935: date => 'immediately prior to specific date:',
1.72 raeburn 936: );
937: my @statuses = &Apache::loncommon::get_env_multiple('form.showcounts');
1.77 raeburn 938: $output .= '<span id="choosewasacctext" class="LC_nobreak">';
1.72 raeburn 939: if ($checked) {
940: $output .= &get_wasactive_text();
941: }
942: $output .= '</span>'.
943: '<div id="choosewasactive" style="display:'.$wasactivedisplay.'">'.
944: '<table>';
945: my @milestones = ('accessend');
946: if (&Apache::lonnet::auto_run(undef,$codedom)) {
947: push(@milestones,'enrollend');
948: }
949: push(@milestones,'date');
950: foreach my $item (@milestones) {
951: my $checked;
952: if ($env{'form.state'} eq 'listing') {
953: if ($env{'form.wasactive'} eq $item) {
954: $checked = ' checked="checked"';
955: }
956: } elsif ($item eq 'accessend') {
957: $checked = ' checked="checked"';
958: }
959: $output .=
960: '<tr><td width="10"> </td><td>'.
961: '<span class="LC_nobreak"><label>'.
962: '<input type="radio" value="'.$item.'" name="wasactive"'.$checked.' />'.
963: $milestonetext{$item}.'</label></span>';
964: if ($item eq 'date') {
965: my $wasactiveon;
966: if (grep(/^Previous$/,@currstatuses)) {
967: $wasactiveon =
968: &Apache::lonhtmlcommon::get_date_from_form('wasactiveon');
969: } else {
970: $wasactiveon = 'now';
971: }
972: $output .= ' '.
973: &Apache::lonhtmlcommon::date_setter('coursecatalog',
974: 'wasactiveon',
975: $wasactiveon,
976: '','','',1,'',
977: '','',1);
978: }
979: $output .= '</td></tr>';
980: }
981: $output .= '</table></div>';
982: }
983: $output .= '<br />';
984: }
985: }
986: }
987: $output .= '</div></td>';
988: } else {
989: $output .= '</td>';
1.33 raeburn 990: }
1.72 raeburn 991: $output .= '</tr></table></fieldset></div>'.
992: '<div style="clear:both;margin:0;"></div>';
1.33 raeburn 993: return $output;
994: }
995:
1.16 raeburn 996: sub user_is_dc {
997: my ($codedom) = @_;
998: if (exists($env{'user.role.dc./'.$codedom.'/'})) {
999: my $livedc = 1;
1000: my $now = time;
1001: my ($start,$end)=split(/\./,$env{'user.role.dc./'.$codedom.'/'});
1002: if ($start && $start>$now) { $livedc = 0; }
1003: if ($end && $end <$now) { $livedc = 0; }
1004: return $livedc;
1005: }
1006: return;
1007: }
1.7 raeburn 1008:
1.86 raeburn 1009: sub canview_all {
1.90 raeburn 1010: my ($knownuser,$codedom) = @_;
1.86 raeburn 1011: my $canviewall = 0;
1012: my $page = 'coursecatalog';
1013: if (&LONCAPA::lonauthcgi::can_view($page)) {
1014: $canviewall = 1;
1015: } elsif (&LONCAPA::lonauthcgi::check_ipbased_access($page)) {
1016: $canviewall= 1;
1.90 raeburn 1017: } elsif (($knownuser) && ($codedom ne '')) {
1018: if (&Apache::lonnet::allowed('dcd',$codedom)) {
1019: $canviewall = 1;
1020: }
1.86 raeburn 1021: }
1022: return $canviewall;
1023: }
1024:
1.72 raeburn 1025: sub get_statustitles {
1026: my ($caller) = @_;
1027: my @status_order = ('Active','Future','Previous');
1028: my %status_title;
1029: if ($caller eq 'filters') {
1030: %status_title = &Apache::lonlocal::texthash(
1031: Previous => 'Show count for past access',
1032: Active => 'Show count for current student access',
1033: Future => 'Show count for future student access',
1034: );
1035: if ($env{'form.currcat_0'} eq 'communities::0') {
1036: $status_title{'Active'} = 'Show count for current member access';
1037: $status_title{'Future'} = 'Show count for future member access';
1038: }
1039: } else {
1040: %status_title = &Apache::lonlocal::texthash(
1041: Previous => 'Previous access',
1042: Active => 'Current access',
1043: Future => 'Future access',
1044: );
1045: }
1046: return (\%status_title,\@status_order);
1047: }
1048:
1049: sub get_wasactive_text {
1050: my $wasacctext = ' -- ';
1051: if ($env{'form.currcat_0'} eq 'communities::0') {
1.74 raeburn 1052: $wasacctext .= &mt('where member access status was current ...');
1.72 raeburn 1053: } else {
1.74 raeburn 1054: $wasacctext .= &mt('where student access status was current ...');
1.72 raeburn 1055: }
1056: return $wasacctext;
1057: }
1058:
1.28 raeburn 1059: sub search_official_courselist {
1.63 raeburn 1060: my ($domain,$numtitles,$codetitles) = @_;
1061: my $instcode = &Apache::courseclassifier::instcode_search_str($domain,$numtitles,$codetitles);
1.32 raeburn 1062: my $showhidden;
1063: if (&user_is_dc($domain)) {
1064: $showhidden = $env{'form.showhidden'};
1065: }
1066: my %courses =
1067: &Apache::lonnet::courseiddump($domain,'.',1,$instcode,'.','.',undef,undef,
1068: 'Course',1,$env{'form.showselfenroll'},undef,
1069: $showhidden,'coursecatalog');
1.7 raeburn 1070: return %courses;
1071: }
1072:
1.28 raeburn 1073: sub search_courselist {
1.36 raeburn 1074: my ($domain,$subcats) = @_;
1.28 raeburn 1075: my $cat_maxdepth = $env{'form.catalog_maxdepth'};
1076: my $filter = $env{'form.currcat_'.$cat_maxdepth};
1.29 raeburn 1077: if (($filter eq '') && ($cat_maxdepth > 0)) {
1078: my $shallower = $cat_maxdepth - 1;
1079: $filter = $env{'form.currcat_'.$shallower};
1080: }
1.28 raeburn 1081: my %courses;
1.36 raeburn 1082: my $filterstr;
1.28 raeburn 1083: if ($filter ne '') {
1.36 raeburn 1084: if ($env{'form.withsubcats'}) {
1085: if (ref($subcats) eq 'HASH') {
1086: if (ref($subcats->{$filter}) eq 'ARRAY') {
1087: $filterstr = join('&',@{$subcats->{$filter}});
1088: if ($filterstr ne '') {
1089: $filterstr = $filter.'&'.$filterstr;
1090: }
1091: } else {
1092: $filterstr = $filter;
1093: }
1094: } else {
1095: $filterstr = $filter;
1096: }
1097: } else {
1098: $filterstr = $filter;
1099: }
1.57 raeburn 1100: my ($showhidden,$typefilter);
1.32 raeburn 1101: if (&user_is_dc($domain)) {
1102: $showhidden = $env{'form.showhidden'};
1103: }
1.57 raeburn 1104: if ($env{'form.currcat_0'} eq 'communities::0') {
1105: $typefilter = 'Community';
1.89 raeburn 1106: } elsif ($env{'form.currcat_0'} eq 'placement::0') {
1107: $typefilter = 'Placement';
1.57 raeburn 1108: } else {
1109: $typefilter = '.';
1110: }
1.32 raeburn 1111: %courses =
1112: &Apache::lonnet::courseiddump($domain,'.',1,'.','.','.',undef,undef,
1.57 raeburn 1113: $typefilter,1,$env{'form.showselfenroll'},
1.36 raeburn 1114: $filterstr,$showhidden,'coursecatalog');
1.28 raeburn 1115: }
1116: return %courses;
1117: }
1.6 raeburn 1118:
1.1 raeburn 1119: sub print_course_listing {
1.86 raeburn 1120: my ($domain,$numtitles,$trails,$allitems,$subcats,$codetitles,$canviewall) = @_;
1.1 raeburn 1121: my $output;
1.7 raeburn 1122: my %courses;
1.15 raeburn 1123: my $knownuser = &user_is_known();
1.86 raeburn 1124: my $canviewall = &canview_all();
1.16 raeburn 1125: my $details = $env{'form.coursenum'};
1.86 raeburn 1126: if (&user_is_dc($domain) || $canviewall) {
1.16 raeburn 1127: if ($env{'form.showdetails'}) {
1128: $details = 1;
1129: }
1130: }
1.7 raeburn 1131: if ($env{'form.coursenum'} ne '') {
1132: %courses = &Apache::lonnet::courseiddump($domain,'.',1,'.','.',
1133: $env{'form.coursenum'},
1.33 raeburn 1134: undef,undef,'.',1);
1.7 raeburn 1135: if (keys(%courses) == 0) {
1.78 bisitz 1136: $output = '<p class="LC_error">';
1.60 raeburn 1137: if ($env{'form.currcat_0'} eq 'communities::0') {
1138: $output .= &mt('The courseID provided does not match a community in this domain.');
1.89 raeburn 1139: } elsif ($env{'form.currcat_0'} eq 'placement::0') {
1140: $output .= &mt('The courseID provided does not match a placement test in this domain.');
1141: } else {
1.60 raeburn 1142: $output .= &mt('The courseID provided does not match a course in this domain.');
1143: }
1.78 bisitz 1144: $output .= '</p>';
1.7 raeburn 1145: return $output;
1146: }
1.6 raeburn 1147: } else {
1.28 raeburn 1148: if ($env{'form.currcat_0'} eq 'instcode::0') {
1.63 raeburn 1149: %courses = &search_official_courselist($domain,$numtitles,$codetitles);
1.28 raeburn 1150: } else {
1.36 raeburn 1151: %courses = &search_courselist($domain,$subcats);
1.28 raeburn 1152: }
1.7 raeburn 1153: if (keys(%courses) == 0) {
1.78 bisitz 1154: $output = '<p class="LC_info">';
1.57 raeburn 1155: if ($env{'form.currcat_0'} eq 'communities::0') {
1.78 bisitz 1156: $output .= &mt('No communities match the criteria you selected.');
1.89 raeburn 1157: } elsif ($env{'form.currcat_0'} eq 'placement::0') {
1158: $output .= &mt('No placement tests match the criteria you selected.');
1.57 raeburn 1159: } else {
1.78 bisitz 1160: $output .= &mt('No courses match the criteria you selected.');
1.57 raeburn 1161: }
1.78 bisitz 1162: $output .= '</p>';
1.7 raeburn 1163: return $output;
1164: }
1.86 raeburn 1165: if (($knownuser) && (!$env{'form.showdetails'}) && (!&user_is_dc($domain)) && (!$canviewall)) {
1.31 bisitz 1166: $output = '<b>'.&mt('Note for students:').'</b> '
1167: .&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.')
1168: .'<br /><br />';
1.8 raeburn 1169: }
1.7 raeburn 1170: }
1.27 raeburn 1171: my $now = time;
1.72 raeburn 1172: $output .= &construct_data_table($knownuser,$domain,\%courses,$details,undef,
1.86 raeburn 1173: $now,$trails,$allitems,$canviewall);
1.41 raeburn 1174: $output .= "\n".'<form name="linklaunch" method="post" action="">'.
1.40 raeburn 1175: '<input type="hidden" name="backto" value="coursecatalog" />'.
1.41 raeburn 1176: '<input type="hidden" name="courseid" value="" />'.
1177: &Apache::lonhtmlcommon::echo_form_input(['catalogfilter','courseid']).'</form>';
1.15 raeburn 1178: return $output;
1179: }
1180:
1181: sub construct_data_table {
1.86 raeburn 1182: my ($knownuser,$domain,$courses,$details,$usersections,$now,$trails,$allitems,$canviewall) = @_;
1.7 raeburn 1183: my %sortname;
1.16 raeburn 1184: if (($details eq '') || ($env{'form.showdetails'})) {
1.7 raeburn 1185: $sortname{'Code'} = 'code';
1.35 raeburn 1186: $sortname{'Categories'} = 'cats';
1.7 raeburn 1187: $sortname{'Title'} = 'title';
1.70 raeburn 1188: $sortname{'Owner & Co-owner(s)'} = 'owner';
1.7 raeburn 1189: }
1.15 raeburn 1190: my $output = &Apache::loncommon::start_data_table().
1191: &Apache::loncommon::start_data_table_header_row();
1.35 raeburn 1192: my @coltitles = ('Count');
1193: if ($env{'form.currcat_0'} eq 'instcode::0') {
1194: push(@coltitles,'Code');
1195: } else {
1196: push(@coltitles,'Categories');
1197: }
1.70 raeburn 1198: push(@coltitles,('Sections','Crosslisted','Title','Owner & Co-owner(s)'));
1.15 raeburn 1199: if (ref($usersections) eq 'HASH') {
1200: $coltitles[1] = 'Your Section';
1201: }
1.7 raeburn 1202: foreach my $item (@coltitles) {
1203: $output .= '<th>';
1204: if (defined($sortname{$item})) {
1205: $output .= '<a href="javascript:changeSort('."'$sortname{$item}'".')">'.&mt($item).'</a>';
1.24 raeburn 1206: } elsif ($item eq 'Count') {
1207: $output .= ' ';
1.7 raeburn 1208: } else {
1209: $output .= &mt($item);
1210: }
1211: $output .= '</th>';
1.1 raeburn 1212: }
1.72 raeburn 1213: my (@fields,%fieldtitles,$wasactiveon);
1.86 raeburn 1214: if ($knownuser || ($canviewall && $details)) {
1.15 raeburn 1215: if ($details) {
1.60 raeburn 1216: if ($env{'form.currcat_0'} eq 'communities::0') {
1.72 raeburn 1217: $output .= '<th>'.&mt('Default Access Dates for Members').'</th>'.
1218: '<th>'.&mt('Member Counts').'</th>';
1.89 raeburn 1219: } elsif ($env{'form.currcat_0'} eq 'placement::0') {
1220: $output .=
1221: '<th>'.&mt('Default Access Dates for Students').'</th>'.
1222: '<th>'.&mt('Student Counts').'</th>';
1.60 raeburn 1223: } else {
1224: $output .=
1225: '<th>'.&mt('Default Access Dates for Students').'</th>'.
1226: '<th>'.&mt('Student Counts').'</th>'.
1227: '<th>'.&mt('Auto-enrollment of[_1]registered students','<br />').'</th>';
1228: }
1.72 raeburn 1229: my ($titlesref,$orderref) = &get_statustitles();
1230: my @statuses;
1.86 raeburn 1231: if (&user_is_dc($domain) || $canviewall) {
1.72 raeburn 1232: @statuses = &Apache::loncommon::get_env_multiple('form.showcounts');
1233: if (grep(/^Previous$/,@statuses)) {
1234: if ($env{'form.wasactive'} eq 'date') {
1235: $wasactiveon =
1236: &Apache::lonhtmlcommon::get_date_from_form('wasactiveon');
1237: } else {
1238: $wasactiveon = $env{'form.wasactive'};
1239: }
1240: }
1241: if (ref($orderref) eq 'ARRAY') {
1242: foreach my $status (@{$orderref}) {
1243: if (grep(/^\Q$status\E$/,@statuses)) {
1244: push(@fields,$status);
1245: }
1246: }
1247: }
1248: } else {
1249: @fields = ('Active','Future');
1250: }
1251: foreach my $status (@fields) {
1252: my $title;
1253: if (ref($titlesref) eq 'HASH') {
1254: $title = $titlesref->{$status};
1255: }
1256: unless ($title) {
1257: $title = &mt($status);
1258: }
1259: $fieldtitles{$status} = $title;
1260: }
1.15 raeburn 1261: } else {
1.27 raeburn 1262: $output .= '<th>'.&mt('Details').'</th>';
1.8 raeburn 1263: }
1.1 raeburn 1264: }
1.27 raeburn 1265: $output .= '<th>'.&mt('Self-enroll (if permitted)').'</th>';
1.7 raeburn 1266: &Apache::loncommon::end_data_table_header_row();
1.73 raeburn 1267: my (%numbers,%creditsum);
1.76 raeburn 1268: my ($showcredits,$defofficial,$defunofficial,$deftextbook);
1.73 raeburn 1269: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
1.89 raeburn 1270: unless (($env{'form.currcat_0'} eq 'communities::0') || ($env{'form.currcat_0'} eq 'placement::0')) {
1.76 raeburn 1271: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'} || $domdefaults{'textbookcredits'}) {
1.73 raeburn 1272: $showcredits = 1;
1273: $defofficial = $domdefaults{'officialcredits'};
1.76 raeburn 1274: $defunofficial = $domdefaults{'unofficialcredits'};
1275: $deftextbook = $domdefaults{'textbookcredits'};
1.73 raeburn 1276: }
1277: }
1.86 raeburn 1278: my %courseinfo = &build_courseinfo_hash($courses,$knownuser,$domain,$canviewall,$details,
1.72 raeburn 1279: $usersections,\@fields,\%fieldtitles,
1.73 raeburn 1280: $wasactiveon,\%numbers,\%creditsum,
1.76 raeburn 1281: $showcredits,$defofficial,$defunofficial,$deftextbook);
1.7 raeburn 1282: my %Sortby;
1.15 raeburn 1283: foreach my $course (sort(keys(%{$courses}))) {
1.7 raeburn 1284: if ($env{'form.sortby'} eq 'code') {
1285: push(@{$Sortby{$courseinfo{$course}{'code'}}},$course);
1.35 raeburn 1286: } elsif ($env{'form.sortby'} eq 'cats') {
1287: push(@{$Sortby{$courseinfo{$course}{'categories'}}},$course);
1.7 raeburn 1288: } elsif ($env{'form.sortby'} eq 'owner') {
1.22 raeburn 1289: push(@{$Sortby{$courseinfo{$course}{'ownerlastnames'}}},$course);
1.7 raeburn 1290: } else {
1.25 raeburn 1291: my $clean_title = $courseinfo{$course}{'title'};
1292: $clean_title =~ s/\W+//g;
1293: if ($clean_title eq '') {
1294: $clean_title = $courseinfo{$course}{'title'};
1295: }
1296: push(@{$Sortby{$clean_title}},$course);
1.7 raeburn 1297: }
1298: }
1299: my @sorted_courses;
1.35 raeburn 1300: if (($env{'form.sortby'} eq 'code') || ($env{'form.sortby'} eq 'owner') ||
1301: ($env{'form.sortby'} eq 'cats')) {
1.7 raeburn 1302: @sorted_courses = sort(keys(%Sortby));
1.6 raeburn 1303: } else {
1.7 raeburn 1304: @sorted_courses = sort { lc($a) cmp lc($b) } (keys(%Sortby));
1.1 raeburn 1305: }
1.24 raeburn 1306: my $count = 1;
1.72 raeburn 1307: my $totalsec = 0;
1.7 raeburn 1308: foreach my $item (@sorted_courses) {
1309: foreach my $course (@{$Sortby{$item}}) {
1310: $output.=&Apache::loncommon::start_data_table_row();
1.35 raeburn 1311: $output.=&courseinfo_row($courseinfo{$course},$knownuser,$details,
1.86 raeburn 1312: \$count,$now,$course,$trails,$allitems,\%numbers,$canviewall);
1.7 raeburn 1313: $output.=&Apache::loncommon::end_data_table_row();
1314: }
1.1 raeburn 1315: }
1.86 raeburn 1316: if (($knownuser || $canviewall) && ($count > 1) && $env{'form.showdetails'}) {
1317: if (&user_is_dc($domain) || $canviewall) {
1.72 raeburn 1318: my %lt = &Apache::lonlocal::texthash (
1319: 'Active' => 'Total current students',
1320: 'Future' => 'Total future students',
1321: 'Previous' => 'Total previous students',
1322: 'courses' => 'Total unique codes and courses without codes',
1323: 'sections' => 'Total sections',
1.73 raeburn 1324: 'xlists' => 'Total cross-listings',
1.72 raeburn 1325: );
1.73 raeburn 1326: if ($showcredits) {
1327: $lt{'cr_Active'} = &mt('Total current student credit hours');
1328: $lt{'cr_Future'} = &mt('Total future student credit hours');
1329: $lt{'cr_Previous'} = &mt('Total previous student credit hours');
1330: }
1.72 raeburn 1331: if ($env{'form.currcat_0'} eq 'communities::0') {
1332: $lt{'courses'} = &mt('Total communities');
1333: $lt{'Active'} = &mt('Total current members');
1334: $lt{'Future'} = &mt('Total future members');
1335: $lt{'Previous'} = &mt('Total previous members');
1.89 raeburn 1336: } elsif ($env{'form.currcat_0'} eq 'placement::0') {
1337: $lt{'courses'} = &mt('Total placement tests');
1.73 raeburn 1338: }
1339: my $colspan = 8;
1340: if ($showcredits) {
1341: $colspan = 4;
1342: }
1.72 raeburn 1343: $output .= '<tr class="LC_footer_row">'.
1344: '<td colspan="2"> </td>'.
1.73 raeburn 1345: '<td colspan="'.$colspan.'">'.
1.72 raeburn 1346: '<table border="0">';
1347: foreach my $item ('courses','sections','xlists') {
1348: $output .= '<tr>'.
1.73 raeburn 1349: '<td>'.$lt{$item}.'</td><td> </td>'.
1.72 raeburn 1350: '<td align="right">'.$numbers{$item}.'</td>'.
1351: '</tr>'."\n";
1352: }
1353: if (@fields > 0) {
1354: foreach my $status (@fields) {
1355: $output .= '<tr>'.
1.73 raeburn 1356: '<td>'.$lt{$status}.'</td><td> </td>'.
1.72 raeburn 1357: '<td align="right">'.$numbers{$status}.'</td>'.
1358: '</tr>'."\n";
1359: }
1360: }
1.73 raeburn 1361: $output .= '</table></td>';
1362: if ($showcredits) {
1363: $output .= '<td colspan="'.$colspan.'" valign="bottom"><table>';
1364: foreach my $status (@fields) {
1365: $output .= '<tr>'.
1366: '<td>'.$lt{'cr_'.$status}.'</td><td> </td>'.
1367: '<td align="right">'.$creditsum{$status}.'</td></tr>';
1368: }
1369: $output .= '</table></td></tr>';
1370: }
1.72 raeburn 1371: }
1372: }
1.7 raeburn 1373: $output .= &Apache::loncommon::end_data_table();
1374: return $output;
1375: }
1376:
1377: sub build_courseinfo_hash {
1.86 raeburn 1378: my ($courses,$knownuser,$domain,$canviewall,$details,$usersections,$fields,$fieldtitles,
1.73 raeburn 1379: $wasactiveon,$numbers,$creditsum,$showcredits,$defofficial,$defunofficial) = @_;
1.1 raeburn 1380: my %courseinfo;
1.7 raeburn 1381: my $now = time;
1.72 raeburn 1382: my $gettotals;
1.86 raeburn 1383: if ((keys(%{$courses}) > 0) && (&user_is_dc($domain) || $canviewall) && ($details)) {
1.72 raeburn 1384: $gettotals = 1;
1385: }
1.73 raeburn 1386: my (%uniquecodes,$nocodes,$defcreds);
1.15 raeburn 1387: foreach my $course (keys(%{$courses})) {
1.1 raeburn 1388: my $descr;
1.22 raeburn 1389: if (ref($courses->{$course}) eq 'HASH') {
1390: $descr = $courses->{$course}{'description'};
1.1 raeburn 1391: }
1392: my $cleandesc=&HTML::Entities::encode($descr,'<>&"');
1393: $cleandesc=~s/'/\\'/g;
1.10 raeburn 1394: $cleandesc =~ s/^\s+//;
1.1 raeburn 1395: my ($cdom,$cnum)=split(/\_/,$course);
1.91 raeburn 1396: my ($instcode,$singleowner,$ttype,$selfenroll_types,$extsyllplain,
1.35 raeburn 1397: $selfenroll_start,$selfenroll_end,@owners,%ownernames,$categories);
1.22 raeburn 1398: if (ref($courses->{$course}) eq 'HASH') {
1399: $descr = $courses->{$course}{'description'};
1.23 raeburn 1400: $instcode = $courses->{$course}{'inst_code'};
1.22 raeburn 1401: $singleowner = $courses->{$course}{'owner'};
1402: $ttype = $courses->{$course}{'type'};
1.27 raeburn 1403: $selfenroll_types = $courses->{$course}{'selfenroll_types'};
1404: $selfenroll_start = $courses->{$course}{'selfenroll_start_date'};
1405: $selfenroll_end = $courses->{$course}{'selfenroll_end_date'};
1.35 raeburn 1406: $categories = $courses->{$course}{'categories'};
1.91 raeburn 1407: $extsyllplain = $courses->{$course}{'extsyllplain'};
1.22 raeburn 1408: push(@owners,$singleowner);
1.67 raeburn 1409: if ($courses->{$course}{'co-owners'} ne '') {
1410: foreach my $item (split(/,/,$courses->{$course}{'co-owners'})) {
1.22 raeburn 1411: push(@owners,$item);
1412: }
1413: }
1414: }
1.72 raeburn 1415: if ($instcode ne '') {
1416: $uniquecodes{$instcode} = 1;
1417: } else {
1418: $nocodes ++;
1419: }
1.22 raeburn 1420: foreach my $owner (@owners) {
1.54 raeburn 1421: my ($ownername,$ownerdom);
1.22 raeburn 1422: if ($owner =~ /:/) {
1423: ($ownername,$ownerdom) = split(/:/,$owner);
1424: } else {
1425: $ownername = $owner;
1426: if ($owner ne '') {
1427: $ownerdom = $cdom;
1428: }
1429: }
1430: if ($ownername ne '' && $ownerdom ne '') {
1431: my %namehash=&Apache::loncommon::getnames($ownername,$ownerdom);
1432: $ownernames{$ownername.':'.$ownerdom} = \%namehash;
1.1 raeburn 1433: }
1434: }
1435: $courseinfo{$course}{'cdom'} = $cdom;
1436: $courseinfo{$course}{'cnum'} = $cnum;
1437: $courseinfo{$course}{'code'} = $instcode;
1.22 raeburn 1438: my @lastnames;
1439: foreach my $owner (keys(%ownernames)) {
1440: if (ref($ownernames{$owner}) eq 'HASH') {
1441: push(@lastnames,$ownernames{$owner}{'lastname'});
1442: }
1443: }
1444: $courseinfo{$course}{'ownerlastnames'} = join(', ',sort(@lastnames));
1.1 raeburn 1445: $courseinfo{$course}{'title'} = $cleandesc;
1.22 raeburn 1446: $courseinfo{$course}{'owner'} = $singleowner;
1.27 raeburn 1447: $courseinfo{$course}{'selfenroll_types'} = $selfenroll_types;
1448: $courseinfo{$course}{'selfenroll_start'} = $selfenroll_start;
1449: $courseinfo{$course}{'selfenroll_end'} = $selfenroll_end;
1.35 raeburn 1450: $courseinfo{$course}{'categories'} = $categories;
1.91 raeburn 1451: $courseinfo{$course}{'extsyllplain'} = $extsyllplain;
1.7 raeburn 1452:
1453: my %coursehash = &Apache::lonnet::dump('environment',$cdom,$cnum);
1454: my @classids;
1455: my @crosslistings;
1.15 raeburn 1456: my ($seclist,$numsec) =
1457: &identify_sections($coursehash{'internal.sectionnums'});
1.7 raeburn 1458: $courseinfo{$course}{'seclist'} = $seclist;
1.15 raeburn 1459: my ($xlist_items,$numxlist) =
1460: &identify_sections($coursehash{'internal.crosslistings'});
1.72 raeburn 1461: if (ref($numbers) eq 'HASH') {
1462: $numbers->{'sections'} += $numsec;
1463: $numbers->{'xlists'} += $numxlist;
1464: }
1.7 raeburn 1465: my $showsyllabus = 1; # default is to include a syllabus link
1466: if (defined($coursehash{'showsyllabus'})) {
1467: $showsyllabus = $coursehash{'showsyllabus'};
1468: }
1469: $courseinfo{$course}{'showsyllabus'} = $showsyllabus;
1.73 raeburn 1470: if ($showcredits) {
1471: if ($coursehash{'internal.defaultcredits'}) {
1472: $courseinfo{$course}{'defaultcredits'} = $coursehash{'internal.defaultcredits'};
1473: } elsif ($instcode ne '') {
1474: $courseinfo{$course}{'defaultcredits'} = $defofficial;
1475: } else {
1476: $courseinfo{$course}{'defaultcredits'} = $defunofficial;
1477: }
1478: $defcreds = $courseinfo{$course}{'defaultcredits'};
1479: }
1.15 raeburn 1480: if (((defined($env{'form.coursenum'}) && ($cnum eq $env{'form.coursenum'}))) ||
1.86 raeburn 1481: (($knownuser || $canviewall) && ($details == 1))) {
1.72 raeburn 1482: my $milestone;
1483: if ($wasactiveon eq 'accessend') {
1484: if ($coursehash{'default_enrollment_end_date'}) {
1485: $milestone = $coursehash{'default_enrollment_end_date'};
1486: } else {
1487: $milestone = time;
1488: }
1489: } elsif ($wasactiveon eq 'enrollend') {
1490: if ($coursehash{'internal.autoend'}) {
1491: $milestone = $coursehash{'internal.autoend'};
1492: } else {
1493: $milestone = time;
1494: }
1495: } else {
1496: $milestone = $wasactiveon;
1497: }
1498: $courseinfo{$course}{'counts'} =
1499: &count_students($cdom,$cnum,$numsec,$fields,$fieldtitles,$gettotals,
1.73 raeburn 1500: $numbers,$creditsum,$showcredits,$defcreds,$milestone);
1.72 raeburn 1501: if ($instcode ne '') {
1502: $courseinfo{$course}{'autoenrollment'} =
1503: &autoenroll_info(\%coursehash,$now,$seclist,$xlist_items,
1504: $instcode,\@owners,$cdom,$cnum);
1505: }
1.15 raeburn 1506: my $startaccess = '';
1507: my $endaccess = '';
1508: my $accessdates;
1509: if ( defined($coursehash{'default_enrollment_start_date'}) ) {
1510: $startaccess = &Apache::lonlocal::locallocaltime($coursehash{'default_enrollment_start_date'});
1511: }
1512: if ( defined($coursehash{'default_enrollment_end_date'}) ) {
1513: $endaccess = &Apache::lonlocal::locallocaltime($coursehash{'default_enrollment_end_date'});
1514: if ($coursehash{'default_enrollment_end_date'} == 0) {
1.34 raeburn 1515: $endaccess = &mt('No ending date');
1.15 raeburn 1516: }
1517: }
1518: if ($startaccess) {
1.42 bisitz 1519: $accessdates .= '<i>'.&mt('From:[_1]','</i> '.$startaccess).'<br />';
1.7 raeburn 1520: }
1.15 raeburn 1521: if ($endaccess) {
1.42 bisitz 1522: $accessdates .= '<i>'.&mt('To:[_1]','</i> '.$endaccess).'<br />';
1.15 raeburn 1523: }
1.34 raeburn 1524: if (($selfenroll_types ne '') &&
1525: ($selfenroll_end > 0 && $selfenroll_end > $now)) {
1526: my ($selfenroll_start_access,$selfenroll_end_access);
1527: if (($coursehash{'default_enrollment_start_date'} ne
1528: $coursehash{'internal.selfenroll_start_access'}) ||
1529: ($coursehash{'default_enrollment_end_date'} ne
1530: $coursehash{'internal.selfenroll_end_access'})) {
1531: if ( defined($coursehash{'internal.selfenroll_start_access'}) ) {
1532: $selfenroll_start_access = &Apache::lonlocal::locallocaltime($coursehash{'internal.selfenroll_start_access'});
1533: }
1534: if ( defined($coursehash{'default_enrollment_end_date'}) ) {
1535: $selfenroll_end_access = &Apache::lonlocal::locallocaltime($coursehash{'internal.selfenroll_end_access'});
1536: if ($coursehash{'internal.selfenroll_end_access'} == 0) {
1537: $selfenroll_end_access = &mt('No ending date');
1538: }
1539: }
1540: if ($selfenroll_start_access || $selfenroll_end_access) {
1541: $accessdates .= '<br/><br /><i>'.&mt('Self-enrollers:').'</i><br />';
1542: if ($selfenroll_start_access) {
1.42 bisitz 1543: $accessdates .= '<i>'.&mt('From:[_1]','</i> '.$selfenroll_start_access).'<br />';
1.34 raeburn 1544: }
1545: if ($selfenroll_end_access) {
1.42 bisitz 1546: $accessdates .= '<i>'.&mt('To:[_1]','</i> '.$selfenroll_end_access).'<br />';
1.34 raeburn 1547: }
1548: }
1549: }
1550: }
1.15 raeburn 1551: $courseinfo{$course}{'access'} = $accessdates;
1.1 raeburn 1552: }
1.7 raeburn 1553: if ($xlist_items eq '') {
1554: $xlist_items = &mt('No');
1.1 raeburn 1555: }
1.7 raeburn 1556: $courseinfo{$course}{'xlist'} = $xlist_items;
1.1 raeburn 1557: }
1.72 raeburn 1558: if (ref($numbers) eq 'HASH') {
1559: $numbers->{'courses'} = $nocodes + scalar(keys(%uniquecodes));
1560: }
1.7 raeburn 1561: return %courseinfo;
1.1 raeburn 1562: }
1563:
1.7 raeburn 1564: sub count_students {
1.73 raeburn 1565: my ($cdom,$cnum,$numsec,$fieldsref,$titlesref,$getcounts,$numbers,$creditsum,
1566: $showcredits,$defcreds,$wasactiveon) = @_;
1.72 raeburn 1567: my $countslist = '<span class="LC_nobreak">'.
1568: &mt('[quant,_1,section,sections,No sections]',$numsec).'</span>';
1569: my (@fields,%titles,$showexpired);
1570: if ((ref($fieldsref) eq 'ARRAY') && (ref($titlesref) eq 'HASH') &&
1571: (ref($numbers) eq 'HASH')) {
1572: @fields = @{$fieldsref};
1573: %titles = %{$titlesref};
1574: if (grep(/^Previous$/,@fields)) {
1575: $showexpired = 1;
1576: }
1577: } else {
1578: return;
1579: }
1.1 raeburn 1580: my $classlist = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.73 raeburn 1581: my (%student_count,%credit_count);
1582: %student_count = (
1.72 raeburn 1583: Active => 0,
1584: Future => 0,
1585: Previous => 0,
1.73 raeburn 1586: );
1587: if ($showcredits) {
1588: %credit_count = (
1589: Active => 0,
1590: Future => 0,
1591: Previous => 0,
1592: );
1593: }
1.1 raeburn 1594: my %idx;
1595: $idx{'status'} = &Apache::loncoursedata::CL_STATUS();
1.72 raeburn 1596: $idx{'end'} = &Apache::loncoursedata::CL_END();
1.73 raeburn 1597: $idx{'credits'} = &Apache::loncoursedata::CL_CREDITS();
1.4 albertel 1598: while (my ($student,$data) = each(%$classlist)) {
1.72 raeburn 1599: my $status = $data->[$idx{'status'}];
1.73 raeburn 1600: my $credits = $data->[$idx{'credits'}];
1601: if ($credits eq '') {
1602: $credits = $defcreds;
1603: }
1.72 raeburn 1604: if ($status eq 'Expired') {
1605: if (($showexpired) &&
1606: ($data->[$idx{'end'}] >= $wasactiveon)) {
1607: $student_count{'Previous'} ++;
1.73 raeburn 1608: if ($showcredits) {
1609: $credit_count{'Previous'} += $credits;
1610: }
1.72 raeburn 1611: }
1612: } else {
1613: $student_count{$status} ++;
1.73 raeburn 1614: if ($showcredits) {
1615: $credit_count{$status} += $credits;
1616: }
1.72 raeburn 1617: }
1.1 raeburn 1618: }
1.72 raeburn 1619: if (@fields) {
1620: $countslist .= ':<br />';
1621: foreach my $status (@fields) {
1622: $countslist .= '<span class="LC_nobreak">'.$titles{$status}.': '.
1623: $student_count{$status}.'</span><br />';
1624: $numbers->{$status} += $student_count{$status};
1.73 raeburn 1625: if ($showcredits) {
1626: $creditsum->{$status} += $credit_count{$status};
1627: }
1.72 raeburn 1628: }
1.1 raeburn 1629: }
1.7 raeburn 1630: return $countslist;
1631: }
1632:
1633: sub courseinfo_row {
1.86 raeburn 1634: my ($info,$knownuser,$details,$countref,$now,$course,$trails,$allitems,$numbers,$canviewall) = @_;
1.7 raeburn 1635: my ($cdom,$cnum,$title,$ownerlast,$code,$owner,$seclist,$xlist_items,
1.91 raeburn 1636: $accessdates,$showsyllabus,$counts,$autoenrollment,$output,$categories,
1637: $extsyllplain);
1.7 raeburn 1638: if (ref($info) eq 'HASH') {
1639: $cdom = $info->{'cdom'};
1640: $cnum = $info->{'cnum'};
1641: $title = $info->{'title'};
1.22 raeburn 1642: $ownerlast = $info->{'ownerlastnames'};
1.7 raeburn 1643: $code = $info->{'code'};
1644: $owner = $info->{'owner'};
1645: $seclist = $info->{'seclist'};
1646: $xlist_items = $info->{'xlist'};
1647: $accessdates = $info->{'access'};
1648: $counts = $info->{'counts'};
1649: $autoenrollment = $info->{'autoenrollment'};
1650: $showsyllabus = $info->{'showsyllabus'};
1.91 raeburn 1651: $extsyllplain = $info->{'extsyllplain'};
1.35 raeburn 1652: $categories = $info->{'categories'};
1.7 raeburn 1653: } else {
1654: $output = '<td colspan="8">'.&mt('No information available for [_1].',
1655: $code).'</td>';
1656: return $output;
1.2 raeburn 1657: }
1.35 raeburn 1658: $output .= '<td>'.$$countref.'</td>';
1659: if ($env{'form.currcat_0'} eq 'instcode::0') {
1660: $output .= '<td>'.$code.'</td>';
1661: } else {
1662: my ($categorylist,@cats);
1663: if ($categories ne '') {
1664: @cats = split('&',$categories);
1665: }
1666: if ((ref($trails) eq 'ARRAY') && (ref($allitems) eq 'HASH')) {
1667: my @categories = map { $trails->[$allitems->{$_}]; } @cats;
1668: $categorylist = join('<br />',@categories);
1669: }
1670: if ($categorylist eq '') {
1671: $categorylist = ' ';
1672: }
1673: $output .= '<td>'.$categorylist.'</td>';
1674: }
1675: $output .= '<td>'.$seclist.'</td>'.
1.7 raeburn 1676: '<td>'.$xlist_items.'</td>'.
1677: '<td>'.$title.' <font size="-2">';
1.2 raeburn 1678: if ($showsyllabus) {
1.91 raeburn 1679: my $usehttp = 0;
1680: if (($ENV{'SERVER_PORT'} == 443) && ($extsyllplain)) {
1681: $usehttp = 1;
1682: }
1683: $output .= '<a href="javascript:ToSyllabus('."'$cdom','$cnum','$usehttp'".')">'.&mt('Syllabus').'</a>';
1.7 raeburn 1684: } else {
1685: $output .= ' ';
1.2 raeburn 1686: }
1687: $output .= '</font></td>'.
1.7 raeburn 1688: '<td>'.$ownerlast.'</td>';
1.86 raeburn 1689: if (($knownuser) || ($canviewall && $details)) {
1.15 raeburn 1690: if ($details) {
1.72 raeburn 1691: $output .=
1692: '<td>'.$accessdates.'</td>'.
1693: '<td>'.$counts.'</td>';
1.89 raeburn 1694: unless (($env{'form.currcat_0'} eq 'communities::0') || ($env{'form.currcat_0'} eq 'placement::0')) {
1.72 raeburn 1695: $output .= '<td>'.$autoenrollment.'</td>';
1.60 raeburn 1696: }
1.15 raeburn 1697: } else {
1698: $output .= "<td><a href=\"javascript:setCourseId('$cnum')\">".&mt('Show more details').'</a></td>';
1.8 raeburn 1699: }
1.7 raeburn 1700: }
1.82 raeburn 1701: my $selfenroll = &selfenroll_status($info,$course);
1702: if ($selfenroll) {
1703: $output .= '<td>'.$selfenroll.'</td>';
1704: } else {
1705: $output .= '<td> </td>';
1706: }
1707: $$countref ++;
1708: return $output;
1709: }
1710:
1711: sub selfenroll_status {
1712: my ($info,$course) = @_;
1713: my $now = time;
1714: my $output;
1715: if (ref($info) eq 'HASH') {
1716: if ($info->{'selfenroll_types'}) {
1717: my $showstart = &Apache::lonlocal::locallocaltime($info->{'selfenroll_start'});
1718: my $showend = &Apache::lonlocal::locallocaltime($info->{'selfenroll_end'});
1719: if (($info->{'selfenroll_end'} > 0) && ($info->{'selfenroll_end'} > $now)) {
1720: if (($info->{'selfenroll_start'} > 0) && ($info->{'selfenroll_start'} > $now)) {
1721: $output = &mt('Starts: [_1]','<span class="LC_cusr_emph">'.$showstart.'</span>').'<br />'.&mt('Ends: [_1]','<span class="LC_cusr_emph">'.$showend.'</span>');
1722: } else {
1723: $output = '<a href="javascript:ToSelfenroll('."'$course'".')">'.
1724: &mt('Enroll in course').'</a><br />';
1725: if ($info->{'selfenroll_end'} == 0) {
1726: $output .= &mt('Available permanently');
1727: } elsif ($info->{'selfenroll_end'} > $now) {
1728: $output .= &mt('Self-enrollment ends: [_1]','<span class="LC_cusr_emph">'.$showend.'</span>');
1729: }
1.66 raeburn 1730: }
1.27 raeburn 1731: }
1732: }
1733: }
1.1 raeburn 1734: return $output;
1735: }
1736:
1737: sub identify_sections {
1738: my ($seclist) = @_;
1739: my @secnums;
1740: if ($seclist =~ /,/) {
1.4 albertel 1741: my @sections = split(/,/,$seclist);
1.1 raeburn 1742: foreach my $sec (@sections) {
1743: $sec =~ s/:[^:]*$//;
1744: push(@secnums,$sec);
1745: }
1746: } else {
1747: if ($seclist =~ m/^([^:]+):/) {
1748: my $sec = $1;
1.4 albertel 1749: if (!grep(/^\Q$sec\E$/,@secnums)) {
1750: push(@secnums,$sec);
1.1 raeburn 1751: }
1752: }
1753: }
1754: @secnums = sort {$a <=> $b} @secnums;
1.39 raeburn 1755: $seclist = join(', ',@secnums);
1.15 raeburn 1756: my $numsec = @secnums;
1757: return ($seclist,$numsec);
1.1 raeburn 1758: }
1759:
1.2 raeburn 1760: sub get_valid_classes {
1.22 raeburn 1761: my ($seclist,$xlist_items,$crscode,$owners,$cdom,$cnum) = @_;
1.2 raeburn 1762: my $response;
1.95 raeburn 1763: my (@sections,@xlists,%possclasses,%okclasses,%validations);
1.2 raeburn 1764: @{$validations{'sections'}} = ();
1765: @{$validations{'xlists'}} = ();
1766: my $totalitems = 0;
1767: if ($seclist) {
1.95 raeburn 1768: @sections = split(/,\s+/,$seclist);
1769: map { $possclasses{$crscode.$_} = 1; } @sections;
1770: }
1771: if ($xlist_items) {
1772: @xlists = split(/,\s+/,$xlist_items);
1773: map { $possclasses{$_} = 1; } @xlists;
1774: }
1775: my %okclasses = &Apache::lonnet::auto_validate_instclasses($cdom,$cnum,$owners,
1776: \%possclasses);
1777: if (keys(%okclasses)) {
1778: foreach my $sec (@sections) {
1.2 raeburn 1779: my $class = $crscode.$sec;
1.95 raeburn 1780: if ($okclasses{$crscode.$sec}) {
1.2 raeburn 1781: if (!grep(/^\Q$sec$\E/,@{$validations{'sections'}})) {
1.4 albertel 1782: push(@{$validations{'sections'}},$sec);
1.2 raeburn 1783: $totalitems ++;
1784: }
1785: }
1786: }
1.95 raeburn 1787: foreach my $item (@xlists) {
1788: if ($okclasses{$item}) {
1789: if (!grep(/^\Q$item\E$/,@{$validations{'xlists'}})) {
1.4 albertel 1790: push(@{$validations{'xlists'}},$item);
1.2 raeburn 1791: $totalitems ++;
1792: }
1793: }
1794: }
1795: }
1796: if ($totalitems > 0) {
1797: if (@{$validations{'sections'}}) {
1.42 bisitz 1798: $response = &mt('Sections:').' '.
1.14 raeburn 1799: join(', ',@{$validations{'sections'}}).'<br />';
1.2 raeburn 1800: }
1801: if (@{$validations{'xlists'}}) {
1.42 bisitz 1802: $response .= &mt('Courses:').' '.
1.14 raeburn 1803: join(', ',@{$validations{'xlists'}});
1.2 raeburn 1804: }
1805: }
1806: return $response;
1807: }
1808:
1.7 raeburn 1809: sub autoenroll_info {
1.22 raeburn 1810: my ($coursehash,$now,$seclist,$xlist_items,$code,$owners,$cdom,$cnum) = @_;
1.7 raeburn 1811: my $autoenrolldates = &mt('Not enabled');
1812: if (defined($coursehash->{'internal.autoadds'}) && $coursehash->{'internal.autoadds'} == 1) {
1813: my ($autostart,$autoend);
1814: if ( defined($coursehash->{'internal.autostart'}) ) {
1815: $autostart = &Apache::lonlocal::locallocaltime($coursehash->{'internal.autostart'});
1816: }
1817: if ( defined($coursehash->{'internal.autoend'}) ) {
1818: $autoend = &Apache::lonlocal::locallocaltime($coursehash->{'internal.autoend'});
1819: }
1820: if ($coursehash->{'internal.autostart'} > $now) {
1821: if ($coursehash->{'internal.autoend'} && $coursehash->{'internal.autoend'} < $now) {
1822: $autoenrolldates = &mt('Not enabled');
1823: } else {
1824: my $valid_classes =
1825: &get_valid_classes($seclist,$xlist_items,$code,
1.22 raeburn 1826: $owners,$cdom,$cnum);
1.7 raeburn 1827: if ($valid_classes ne '') {
1.42 bisitz 1828: $autoenrolldates = &mt('Not enabled').'<br />'
1829: .&mt('Starts: [_1]',$autostart)
1830: .'<br />'.$valid_classes;
1831: }
1.7 raeburn 1832: }
1833: } else {
1834: if ($coursehash->{'internal.autoend'} && $coursehash->{'internal.autoend'} < $now) {
1.42 bisitz 1835: $autoenrolldates = &mt('Not enabled').'<br />'
1836: .&mt('Ended: [_1]',$autoend);
1.7 raeburn 1837: } else {
1838: my $valid_classes = &get_valid_classes($seclist,$xlist_items,
1.22 raeburn 1839: $code,$owners,$cdom,$cnum);
1.7 raeburn 1840: if ($valid_classes ne '') {
1.42 bisitz 1841: $autoenrolldates = &mt('Currently enabled').'<br />'.
1.7 raeburn 1842: $valid_classes;
1843: }
1844: }
1845: }
1846: }
1847: return $autoenrolldates;
1848: }
1849:
1.8 raeburn 1850: sub user_is_known {
1851: my $known = 0;
1852: if ($env{'user.name'} ne '' && $env{'user.name'} ne 'public'
1853: && $env{'user.domain'} ne '' && $env{'user.domain'} ne 'public') {
1854: $known = 1;
1855: }
1856: return $known;
1857: }
1858:
1.1 raeburn 1859: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>