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