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