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