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