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