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