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