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