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