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