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