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