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