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