Annotation of loncom/interface/coursecatalog.pm, revision 1.59
1.17 albertel 1: # The LearningOnline Network with CAPA
2: # Handler for displaying the course catalog interface
3: #
1.59 ! droeschl 4: # $Id: coursecatalog.pm,v 1.58 2009/11/23 22:02:50 raeburn Exp $
1.1 raeburn 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
29: package Apache::coursecatalog;
30:
31: use strict;
32: use lib qw(/home/httpd/lib/perl);
33: use Apache::Constants qw(:common);
34: use Apache::loncommon;
1.7 raeburn 35: use Apache::lonhtmlcommon;
1.1 raeburn 36: use Apache::lonnet;
37: use Apache::lonlocal;
1.6 raeburn 38: use Apache::courseclassifier;
1.1 raeburn 39: use Apache::lonacc;
40: use LONCAPA;
41:
42: sub handler {
43: my ($r) = @_;
44: &Apache::loncommon::content_type($r,'text/html');
45: $r->send_http_header;
46: if ($r->header_only) {
47: return OK;
48: }
1.21 albertel 49: my $handle = &Apache::lonnet::check_for_valid_session($r);
1.8 raeburn 50: my $lonidsdir=$r->dir_config('lonIDsDir');
1.21 albertel 51: if ($handle ne '') {
1.8 raeburn 52: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
53: }
1.1 raeburn 54: &Apache::lonacc::get_posted_cgi($r);
55: &Apache::lonlocal::get_language_handle($r);
1.38 raeburn 56: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
57: ['sortby','showdom']);
1.28 raeburn 58:
59: my $codedom = &Apache::lonnet::default_login_domain();
1.19 raeburn 60:
61: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne 'public')) {
62: $codedom = $env{'user.domain'};
63: if ($env{'request.role.domain'} ne '') {
64: $codedom = $env{'request.role.domain'};
65: }
66: }
1.7 raeburn 67: my $formname = 'coursecatalog';
1.28 raeburn 68: if ($env{'form.showdom'} ne '') {
69: if (&Apache::lonnet::domain($env{'form.showdom'}) ne '') {
70: $codedom = $env{'form.showdom'};
71: }
72: }
1.20 albertel 73: my $domdesc = &Apache::lonnet::domain($codedom,'description');
1.7 raeburn 74: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.35 raeburn 75:
76: my %domconfig =
77: &Apache::lonnet::get_dom('configuration',['coursecategories'],$codedom);
1.36 raeburn 78: my (@cats,@trails,%allitems,%idx,@jsarray,%subcathash,$cathash);
1.35 raeburn 79: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
80: $cathash = $domconfig{'coursecategories'}{'cats'};
81: } else {
82: $cathash = {};
83: }
1.36 raeburn 84: my $subcats;
85: if ($env{'form.withsubcats'}) {
86: $subcats = \%subcathash;
87: }
1.35 raeburn 88: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems,
1.36 raeburn 89: \%idx,\@jsarray,$subcats);
1.8 raeburn 90: if ($env{'form.coursenum'} ne '' && &user_is_known()) {
1.35 raeburn 91: &course_details($r,$codedom,$formname,$domdesc,\@trails,\%allitems);
1.7 raeburn 92: } else {
1.46 raeburn 93: my ($catlinks,$has_subcats,$selitem) = &category_breadcrumbs($codedom,@cats);
1.28 raeburn 94: my $catjs = <<"ENDSCRIPT";
95:
96: function setCatDepth(depth) {
97: document.coursecats.catalog_maxdepth.value = depth;
1.36 raeburn 98: if (depth == '') {
99: document.coursecats.currcat_0.value = '';
100: }
1.28 raeburn 101: document.coursecats.submit();
102: return;
103: }
104:
1.33 raeburn 105: function changeSort(caller) {
106: document.$formname.sortby.value = caller;
107: document.$formname.submit();
108: }
1.40 raeburn 109:
1.33 raeburn 110: function setCourseId(caller) {
111: document.$formname.coursenum.value = caller;
112: document.$formname.submit();
1.37 raeburn 113: }
114:
115: ENDSCRIPT
1.41 raeburn 116: $catjs .= &courselink_javascript();
1.28 raeburn 117: my $numtitles;
118: if ($env{'form.currcat_0'} eq 'instcode::0') {
119: $numtitles = &instcode_course_selector($r,$codedom,$formname,$domdesc,
120: $catlinks,$catjs);
121: if ($env{'form.state'} eq 'listing') {
122: $r->print(&print_course_listing($codedom,$numtitles));
123: }
124: } else {
125: my (%add_entries);
1.50 raeburn 126: my ($currdepth,$deeper) = &get_depth_values();
1.46 raeburn 127: if ($selitem) {
1.50 raeburn 128: my $alert = &mt('Choose a subcategory to display');
129: if (!$deeper) {
130: $alert = &mt('Choose a category to display');
131: }
1.46 raeburn 132: $catjs .= <<ENDJS;
133: function check_selected() {
134: if (document.coursecats.$selitem.options[document.coursecats.$selitem.selectedIndex].value == "") {
1.50 raeburn 135: alert('$alert');
1.46 raeburn 136: return false;
137: }
138: }
139: ENDJS
140: }
1.28 raeburn 141: $catjs = '<script type="text/javascript">'."\n".$catjs."\n".'</script>';
142: &cat_header($r,$codedom,$catjs,\%add_entries,$catlinks);
143: if ($env{'form.currcat_0'} ne '') {
1.33 raeburn 144: $r->print('<form name="'.$formname.
145: '" method="post" action="/adm/coursecatalog">'.
1.36 raeburn 146: &additional_filters($codedom,$has_subcats)."\n");
1.33 raeburn 147: $r->print('<input type="hidden" name="catalog_maxdepth" value="'.
148: $deeper.'" />'."\n");
149: for (my $i=0; $i<$deeper; $i++) {
150: $r->print('<input type="hidden" name="currcat_'.$i.'" value="'.$env{'form.currcat_'.$i}.'" />'."\n");
151: }
1.57 raeburn 152: my $display_button;
153: if ($env{'form.currcat_0'} eq 'communities::0') {
154: $display_button = &mt('Display communities');
155: } else {
156: $display_button = &mt('Display courses');
157: }
1.33 raeburn 158: $r->print('<input type="hidden" name="coursenum" value="" />'."\n".
159: '<input type="hidden" name="sortby" value="" />'."\n".
160: '<input type="hidden" name="state" value="listing" />'."\n".
161: '<input type="hidden" name="showdom" value="'.
162: $env{'form.showdom'}.'" />'.
163: '<input type="submit" name="catalogfilter" value="'.
1.57 raeburn 164: $display_button.'" /></form><br /><br />');
1.33 raeburn 165: }
166: if ($env{'form.state'} eq 'listing') {
1.36 raeburn 167: $r->print(&print_course_listing($codedom,undef,\@trails,\%allitems,$subcats));
1.28 raeburn 168: }
1.18 raeburn 169: }
1.7 raeburn 170: }
1.32 raeburn 171: $r->print('<br />'.&Apache::loncommon::end_page());
1.7 raeburn 172: return OK;
173: }
174:
175: sub course_details {
1.35 raeburn 176: my ($r,$codedom,$formname,$domdesc,$trails,$allitems) = @_;
1.7 raeburn 177: my $output;
178: my %add_entries = (topmargin => "0",
179: marginheight => "0",);
1.40 raeburn 180: my $js = '<script type="text/javascript">'."\n".
1.41 raeburn 181: &courselink_javascript().'</script>'."\n";
1.7 raeburn 182: my $start_page =
1.56 bisitz 183: &Apache::loncommon::start_page('Course/Community Catalog',$js,
1.59 ! droeschl 184: {'add_entries' => \%add_entries, });
1.7 raeburn 185: $r->print($start_page);
1.19 raeburn 186: if ($env{'form.numtitles'} > 0) {
187: &Apache::lonhtmlcommon::add_breadcrumb
188: ({href=>"/adm/coursecatalog",
1.56 bisitz 189: text=>"Course/Community Catalog"});
1.19 raeburn 190: }
1.7 raeburn 191: &Apache::lonhtmlcommon::add_breadcrumb
1.19 raeburn 192: ({href=>"javascript:document.$formname.submit()",
1.7 raeburn 193: text=>"Course listing"},
194: {text=>"Course details"});
1.55 raeburn 195: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course/Community Catalog'));
1.7 raeburn 196: $r->print('<br />'.&mt('Detailed course information:').'<br /><br />'.
1.35 raeburn 197: &print_course_listing($codedom,undef,$trails,$allitems).
198: '<br /><br />');
1.40 raeburn 199: $r->print('<form name="'.$formname.'" method="post" action="/adm/coursecatalog">'.
200: '<a href = "javascript:document.coursecatalog.submit()">'.
1.7 raeburn 201: &mt('Back to course listing').'</a>'.
1.41 raeburn 202: &Apache::lonhtmlcommon::echo_form_input(['coursenum','catalogfilter',
203: 'showdetails','courseid']).'</form>');
1.40 raeburn 204: return;
205: }
206:
1.41 raeburn 207: sub courselink_javascript {
1.40 raeburn 208: return <<"END";
209:
210: function ToSyllabus(cdom,cnum) {
211: if (cdom == '' || cdom == null) {
212: return;
213: }
214: if (cnum == '' || cnum == null) {
215: return;
216: }
1.41 raeburn 217: document.linklaunch.action = "/public/"+cdom+"/"+cnum+"/syllabus";
218: document.linklaunch.submit();
219: }
220:
221: function ToSelfenroll(courseid) {
222: if (courseid == '') {
223: return;
224: }
225: document.linklaunch.action = "/adm/selfenroll";
226: document.linklaunch.courseid.value = courseid;
227: document.linklaunch.submit();
1.40 raeburn 228: }
229:
230: END
1.7 raeburn 231: }
232:
1.28 raeburn 233: sub instcode_course_selector {
234: my ($r,$codedom,$formname,$domdesc,$catlinks,$catjs) = @_;
1.1 raeburn 235: my %coursecodes = ();
236: my %codes = ();
237: my @codetitles = ();
238: my %cat_titles = ();
239: my %cat_order = ();
1.6 raeburn 240: my %cat_items;
1.1 raeburn 241: my $caller = 'global';
242: my $format_reply;
1.30 raeburn 243: my %add_entries = (topmargin => "0",
244: marginheight => "0",);
1.51 raeburn 245: my ($jscript,$totcodes,$numtitles,$lasttitle) =
246: &Apache::courseclassifier::instcode_selectors_data($codedom,$formname,
247: \%cat_items,\@codetitles,\%cat_titles,\%cat_order);
248: my $js = '<script type"text/javascript">'."\n$jscript\n$catjs\n".
1.30 raeburn 249: '</script>';
1.51 raeburn 250: if ($totcodes) {
1.18 raeburn 251: if (($env{'form.state'} eq 'listing') && ($numtitles > 0)) {
1.7 raeburn 252: $add_entries{'onLoad'} = 'setElements()';
253: }
1.28 raeburn 254: &cat_header($r,$codedom,$js,\%add_entries,$catlinks,$numtitles);
255: my $cat_maxdepth = $env{'form.catalog_maxdepth'};
256: $r->print('<form name="'.$formname.'" method="post" action="/adm/coursecatalog">'.
1.32 raeburn 257: '<input type="hidden" name="catalog_maxdepth" value="'.$cat_maxdepth.'" />'."\n".
258: '<input type="hidden" name="showdom" value="'.$env{'form.showdom'}.'" />'."\n".
259: '<input type="hidden" name="currcat_0" value="instcode::0" />'.
1.33 raeburn 260: &additional_filters($codedom));
1.1 raeburn 261: if ($numtitles > 0) {
1.51 raeburn 262: $r->print('<b>'.&mt('Choose which course(s) to list.').'</b><br />'.
263: &Apache::courseclassifier::build_instcode_selectors($numtitles,
264: $lasttitle,\%cat_items,\@codetitles,\%cat_titles,\%cat_order));
1.18 raeburn 265: }
1.33 raeburn 266: $r->print('<input type="hidden" name="coursenum" value="" />'."\n".
267: '<input type="hidden" name="sortby" value="" />'."\n".
268: '<input type="hidden" name="state" value="listing" />'."\n".
269: '<input type="hidden" name="form.currcat_0" value="instcode::0" />'."\n".
270: '<input type="submit" name="catalogfilter" value="'.
271: &mt('Display courses').'" />'.
272: '<input type="hidden" name="numtitles" value="'.$numtitles.
1.37 raeburn 273: '" /></form><br /><br />');
1.5 raeburn 274: } else {
1.45 raeburn 275: $js = '<script type"text/javascript">'."\n$catjs\n".'</script>';
1.30 raeburn 276: &cat_header($r,$codedom,$js,\%add_entries,$catlinks,$numtitles);
277: my $cat_maxdepth = $env{'form.catalog_maxdepth'};
278: $r->print('<form name="'.$formname.'" method="post" action="/adm/coursecatalog">'.
279: '<input type="hidden" name="catalog_maxdepth" value="'.$cat_maxdepth.'" />'.
280: '<input type="hidden" name="showdom" value="'.$env{'form.showdom'}.'" />'.
281: '<input type="hidden" name="currcat_0" value="instcode::0" />');
282: $r->print('<br />'.&mt('No official courses to display for [_1].',$domdesc).'</form>');
1.1 raeburn 283: }
1.18 raeburn 284: return $numtitles;
1.1 raeburn 285: }
286:
1.28 raeburn 287: sub cat_header {
288: my ($r,$codedom,$js,$add_entries,$catlinks,$numtitles) = @_;
289: my $start_page =
1.49 schafran 290: &Apache::loncommon::start_page('Other',$js,
1.59 ! droeschl 291: { 'add_entries' => $add_entries, });
1.28 raeburn 292: $r->print($start_page);
293: if ($env{'form.state'} eq 'listing') {
294: if ($numtitles > 0) {
295: &Apache::lonhtmlcommon::add_breadcrumb
296: ({href=>"/adm/coursecatalog",
1.56 bisitz 297: text=>"Course/Community Catalog"},
1.28 raeburn 298: {text=>"Course listing"});
299: } else {
300: &Apache::lonhtmlcommon::add_breadcrumb
301: ({text=>"Course listing"});
302: }
303: } else {
304: &Apache::lonhtmlcommon::add_breadcrumb
305: ({href=>"/adm/coursecatalog",
1.56 bisitz 306: text=>"Course/Community Catalog"});
1.28 raeburn 307: }
1.55 raeburn 308: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course/Community Catalog'));
1.47 raeburn 309: my $onchange;
1.52 www 310: unless ($env{'form.interface'} eq 'textual') {
1.53 raeburn 311: $onchange = 'this.form.submit()';
1.47 raeburn 312: }
1.34 raeburn 313: $r->print('<form name="coursecatdom" method="post" action="/adm/coursecatalog">'.
314: '<table border="0"><tr><td><b>'.&mt('Domain:').'</b></td><td>'.
1.47 raeburn 315: &Apache::loncommon::select_dom_form($codedom,'showdom','',1,$onchange));
316: if (!$onchange) {
317: $r->print(' <input type="submit" name="godom" value="'.&mt('Change').'" />');
318: }
319: $r->print('</td></tr></table></form>'.
1.46 raeburn 320: '<form name="coursecats" method="post" action="/adm/coursecatalog"'.
1.48 raeburn 321: ' onsubmit="return check_selected();">'.
1.34 raeburn 322: '<table border="0"><tr>'.$catlinks.'</tr></table></form>');
1.28 raeburn 323: return;
324: }
325:
326: sub category_breadcrumbs {
1.35 raeburn 327: my ($dom,@cats) = @_;
1.44 raeburn 328: my $crumbsymbol = ' ▶ ';
1.33 raeburn 329: my ($currdepth,$deeper) = &get_depth_values();
1.57 raeburn 330: my $currcat_str =
331: '<input type="hidden" name="catalog_maxdepth" value="'.$deeper.'" />'.
332: '<input type="hidden" name="showdom" value="'.$dom.'" />';
1.58 raeburn 333: my $catlinks = '<td valign="top"><b>'.&mt('Catalog:').'</b></td><td><table><tr><td>';
1.36 raeburn 334: my $has_subcats;
1.46 raeburn 335: my $selitem;
1.58 raeburn 336: if (ref($cats[0]) eq 'ARRAY') {
337: if (@{$cats[0]} == 0) {
338: $catlinks .= &mt('No categories defined in this domain');
339: } elsif (@{$cats[0]} == 1) {
340: if ($cats[0][0] eq 'instcode') {
341: $catlinks .= &mt('Official courses (with institutional codes)');
342: $env{'form.currcat_0'} = 'instcode::0';
343: } elsif ($cats[0][0] eq 'communities') {
344: $catlinks .= &mt('Communities');
345: $env{'form.currcat_0'} = 'communities::0';
346: } else {
347: my $name = $cats[0][0];
348: my $item = &escape($name).'::0';
349: $catlinks .= $name;
350: $env{'form.currcat_0'} = $item;
1.46 raeburn 351: }
1.58 raeburn 352: $currcat_str .= '<input type="hidden" name="currcat_0" value="'.$env{'form.currcat_0'}.'" />';
1.28 raeburn 353: } else {
1.58 raeburn 354: $catlinks .= &main_category_selector(@cats);
355: if (($env{'form.currcat_0'} ne '') &&
356: ($env{'form.currcat_0'} ne 'instcode::0')) {
357: $catlinks .= $crumbsymbol;
358: } else {
359: $catlinks .= '</td>';
360: }
361: }
362: } else {
363: $catlinks .= &mt('Official courses (with institutional codes)');
364: $env{'form.currcat_0'} = 'instcode::0';
365: $currcat_str .= '<input type="hidden" name="currcat_0" value="'.$env{'form.currcat_0'}.'" />';
366: }
367: if ($deeper) {
368: for (my $i=1; $i<=$deeper; $i++) {
369: my $shallower = $i-1;
370: next if ($shallower == 0);
1.28 raeburn 371: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$env{'form.currcat_'.$shallower});
1.58 raeburn 372: if ($cat ne '') {
373: $catlinks .= '<td valign="top">'.
374: '<select name="currcat_'.$shallower.'" onchange="'.
375: 'setCatDepth('."'$shallower'".');this.form.submit();">';
376: if (ref($cats[$shallower]{$container}) eq 'ARRAY') {
377: $catlinks .= '<option value="">'.&mt('De-select').'</option>';
378: for (my $j=0; $j<@{$cats[$shallower]{$container}}; $j++) {
379: my $name = $cats[$shallower]{$container}[$j];
380: my $item = &escape($name).':'.$container.':'.$shallower;
381: my $selected = '';
382: if ($item eq $env{'form.currcat_'.$shallower}) {
383: $selected = ' selected="selected"';
384: }
385: $catlinks .=
386: '<option value="'.$item.'"'.$selected.'>'.$name.'</option>';
1.28 raeburn 387: }
388: }
1.58 raeburn 389: $catlinks .= '</select>';
1.28 raeburn 390: }
1.58 raeburn 391: unless ($i == $deeper) {
392: $catlinks .= $crumbsymbol;
393: }
1.28 raeburn 394: }
1.29 raeburn 395: my ($cat,$container,$depth);
396: if ($env{'form.currcat_'.$currdepth} eq '') {
397: my $shallower = $currdepth - 1;
398: ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$env{'form.currcat_'.$shallower});
399: } else {
400: ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$env{'form.currcat_'.$currdepth});
401: }
1.58 raeburn 402: my $deeperlevel = $depth +1;
403: if (ref($cats[$deeperlevel]{$cat}) eq 'ARRAY') {
1.36 raeburn 404: $has_subcats = 1;
1.46 raeburn 405: my $buttontext = &mt('Show subcategories');
1.58 raeburn 406: my $selitem = 'currcat_'.$deeperlevel;
407: $catlinks .= ' <select name="'.$selitem.'" onchange="this.form.submit()">';
408: if (@{$cats[$deeperlevel]{$cat}}) {
1.46 raeburn 409: $catlinks .= '<option value="" selected="selected">'.
1.58 raeburn 410: &mt('Subcategory ...').'</option>';
1.46 raeburn 411: }
1.58 raeburn 412: for (my $k=0; $k<@{$cats[$deeperlevel]{$cat}}; $k++) {
413: my $name = $cats[$deeperlevel]{$cat}[$k];
414: my $item = &escape($name).':'.&escape($cat).':'.$deeperlevel;
1.28 raeburn 415: $catlinks .= '<option value="'.$item.'">'.$name.'</option>'."\n";
416: }
1.58 raeburn 417: $catlinks .= '</select>'."\n";
1.46 raeburn 418: } elsif ($cat ne 'instcode') {
419: $catlinks .= ' '.&mt('(No subcategories)');
1.28 raeburn 420: }
1.58 raeburn 421: } else {
422: $selitem = 'currcat_0';
1.28 raeburn 423: }
424: $catlinks .= $currcat_str.'</td></tr></table></td>';
1.46 raeburn 425: return ($catlinks,$has_subcats,$selitem);
1.28 raeburn 426: }
427:
1.58 raeburn 428: sub main_category_selector {
429: my (@cats) = @_;
430: my $maincatlinks = '<select name="currcat_0" onchange="setCatDepth('."'0'".');this.form.submit();">'."\n";
431: if (ref($cats[0]) eq 'ARRAY') {
432: if (@{$cats[0]} > 1) {
433: my $selected = '';
434: if ($env{'form.currcat_0'} eq '') {
435: $selected = ' selected="selected"';
436: }
437: $maincatlinks .=
438: '<option value=""'.$selected.'>'.&mt('Select').'</option>'."\n";
439: }
440: for (my $i=0; $i<@{$cats[0]}; $i++) {
441: my $name = $cats[0][$i];
442: my $item = &escape($name).'::0';
443: my $selected;
444: if ($env{'form.currcat_0'} eq $item) {
445: $selected = ' selected="selected"';
446: }
447: $maincatlinks .= '<option value="'.$item.'"'.$selected.'>';
448: if ($name eq 'instcode') {
449: $maincatlinks .= &mt('Official courses (with institutional codes)');
450: } elsif ($name eq 'communities') {
451: $maincatlinks .= &mt('Communities');
452: } else {
453: $maincatlinks .= $name;
454: }
455: $maincatlinks .= '</option>'."\n";
456: }
457: $maincatlinks .= '</select>'."\n";
458: }
459: return $maincatlinks;
460: }
461:
1.33 raeburn 462: sub get_depth_values {
463: my $currdepth = 0;
464: my $deeper = 0;
465: if ($env{'form.catalog_maxdepth'} ne '') {
466: $currdepth = $env{'form.catalog_maxdepth'};
467: if ($env{'form.currcat_'.$currdepth} eq '') {
468: $deeper = $currdepth;
469: } else {
470: $deeper = $currdepth + 1;
471: }
472: }
473: return ($currdepth,$deeper);
474: }
475:
476: sub additional_filters {
1.36 raeburn 477: my ($codedom,$has_subcats) = @_;
1.33 raeburn 478: my $output = '<table>';
1.36 raeburn 479: if (($env{'form.currcat_0'} ne 'instcode::0') &&
480: ($env{'form.currcat_0'} ne '') && ($has_subcats)) {
481: my $include_subcat_status;
482: if ($env{'form.withsubcats'}) {
483: $include_subcat_status = 'checked="checked" ';
484: }
485: my $counter = $env{'form.catalog_maxdepth'};
486: if ($counter > 0) {
487: if ($env{'form.state'} eq 'listing') {
488: $counter --;
489: } elsif ($env{'form.currcat_'.$counter} eq '') {
490: $counter --;
491: }
492: }
493: my ($catname) = split(/:/,$env{'form.currcat_'.$counter});
494: if ($catname ne '') {
495: $output .= '<tr><td><label>'.
496: '<input type="checkbox" name="withsubcats" value="1" '.
497: $include_subcat_status.'/>'.
1.38 raeburn 498: &mt('Include subcategories within "[_1]"',
499: &unescape($catname)).'</label></td></tr>';
1.36 raeburn 500: }
501: }
1.33 raeburn 502: my $show_selfenroll_status;
503: if ($env{'form.showselfenroll'}) {
504: $show_selfenroll_status = 'checked="checked" ';
505: }
1.57 raeburn 506: my $selfenroll_text;
507: if ($env{'form.currcat_0'} eq 'communities::0') {
508: $selfenroll_text = &mt('Only show communities which allow self-enrollment');
509: } else {
510: $selfenroll_text = &mt('Only show courses which allow self-enrollment');
511: }
1.36 raeburn 512: $output .= '<tr><td>'.
513: '<label><input type="checkbox" name="showselfenroll" value="1" '.
1.57 raeburn 514: $show_selfenroll_status.'/>'.$selfenroll_text.
1.36 raeburn 515: '</label></td></tr>';
1.33 raeburn 516: if (&user_is_dc($codedom)) {
517: my $showdetails_status;
518: if ($env{'form.showdetails'}) {
519: $showdetails_status = 'checked="checked" ';
520: }
521: my $showhidden_status;
522: if ($env{'form.showhidden'}) {
523: $showhidden_status = 'checked="checked" ';
524: }
525: my $dc_title = &Apache::lonnet::plaintext('dc');
1.57 raeburn 526: my ($details_text,$hidden_text);
527: if ($env{'form.currcat_0'} eq 'communities::0') {
528: $details_text = &mt('Show full details for each community ([_1] only)',$dc_title);
529: $hidden_text = &mt('Include communities set to be hidden from catalog ([_1] only)',$dc_title);
530: } else {
531: $details_text = &mt('Show full details for each course ([_1] only)',$dc_title);
532: $hidden_text = &mt('Include courses set to be hidden from catalog ([_1] only)',$dc_title);
533: }
1.33 raeburn 534: $output .= '<tr><td>'."\n".
535: '<label><input type="checkbox" name="showdetails" value="1" '.
1.57 raeburn 536: $showdetails_status.'/>'.$details_text.
1.33 raeburn 537: '</label>'."\n".'</td></tr><tr><td>'.
538: '<label><input type="checkbox" name="showhidden" value="1" '.
1.57 raeburn 539: $showhidden_status.'/>'.$hidden_text.
1.33 raeburn 540: '</label>'."\n".'</td></tr>';
541: }
1.36 raeburn 542: $output .= '</table><br />';
1.33 raeburn 543: return $output;
544: }
545:
1.16 raeburn 546: sub user_is_dc {
547: my ($codedom) = @_;
548: if (exists($env{'user.role.dc./'.$codedom.'/'})) {
549: my $livedc = 1;
550: my $now = time;
551: my ($start,$end)=split(/\./,$env{'user.role.dc./'.$codedom.'/'});
552: if ($start && $start>$now) { $livedc = 0; }
553: if ($end && $end <$now) { $livedc = 0; }
554: return $livedc;
555: }
556: return;
557: }
1.7 raeburn 558:
1.28 raeburn 559: sub search_official_courselist {
1.18 raeburn 560: my ($domain,$numtitles) = @_;
1.51 raeburn 561: my $instcode = &Apache::courseclassifier::instcode_search_str($domain,$numtitles);
1.32 raeburn 562: my $showhidden;
563: if (&user_is_dc($domain)) {
564: $showhidden = $env{'form.showhidden'};
565: }
566: my %courses =
567: &Apache::lonnet::courseiddump($domain,'.',1,$instcode,'.','.',undef,undef,
568: 'Course',1,$env{'form.showselfenroll'},undef,
569: $showhidden,'coursecatalog');
1.7 raeburn 570: return %courses;
571: }
572:
1.28 raeburn 573: sub search_courselist {
1.36 raeburn 574: my ($domain,$subcats) = @_;
1.28 raeburn 575: my $cat_maxdepth = $env{'form.catalog_maxdepth'};
576: my $filter = $env{'form.currcat_'.$cat_maxdepth};
1.29 raeburn 577: if (($filter eq '') && ($cat_maxdepth > 0)) {
578: my $shallower = $cat_maxdepth - 1;
579: $filter = $env{'form.currcat_'.$shallower};
580: }
1.28 raeburn 581: my %courses;
1.36 raeburn 582: my $filterstr;
1.28 raeburn 583: if ($filter ne '') {
1.36 raeburn 584: if ($env{'form.withsubcats'}) {
585: if (ref($subcats) eq 'HASH') {
586: if (ref($subcats->{$filter}) eq 'ARRAY') {
587: $filterstr = join('&',@{$subcats->{$filter}});
588: if ($filterstr ne '') {
589: $filterstr = $filter.'&'.$filterstr;
590: }
591: } else {
592: $filterstr = $filter;
593: }
594: } else {
595: $filterstr = $filter;
596: }
597: } else {
598: $filterstr = $filter;
599: }
1.57 raeburn 600: my ($showhidden,$typefilter);
1.32 raeburn 601: if (&user_is_dc($domain)) {
602: $showhidden = $env{'form.showhidden'};
603: }
1.57 raeburn 604: if ($env{'form.currcat_0'} eq 'communities::0') {
605: $typefilter = 'Community';
606: } else {
607: $typefilter = '.';
608: }
1.32 raeburn 609: %courses =
610: &Apache::lonnet::courseiddump($domain,'.',1,'.','.','.',undef,undef,
1.57 raeburn 611: $typefilter,1,$env{'form.showselfenroll'},
1.36 raeburn 612: $filterstr,$showhidden,'coursecatalog');
1.28 raeburn 613: }
614: return %courses;
615: }
1.6 raeburn 616:
1.1 raeburn 617: sub print_course_listing {
1.36 raeburn 618: my ($domain,$numtitles,$trails,$allitems,$subcats) = @_;
1.1 raeburn 619: my $output;
1.7 raeburn 620: my %courses;
1.15 raeburn 621: my $knownuser = &user_is_known();
1.16 raeburn 622: my $details = $env{'form.coursenum'};
623: if (&user_is_dc($domain)) {
624: if ($env{'form.showdetails'}) {
625: $details = 1;
626: }
627: }
1.7 raeburn 628: if ($env{'form.coursenum'} ne '') {
629: %courses = &Apache::lonnet::courseiddump($domain,'.',1,'.','.',
630: $env{'form.coursenum'},
1.33 raeburn 631: undef,undef,'.',1);
1.7 raeburn 632: if (keys(%courses) == 0) {
633: $output .= &mt('The courseID provided does not match a course in this domain.');
634: return $output;
635: }
1.6 raeburn 636: } else {
1.28 raeburn 637: if ($env{'form.currcat_0'} eq 'instcode::0') {
638: %courses = &search_official_courselist($domain,$numtitles);
639: } else {
1.36 raeburn 640: %courses = &search_courselist($domain,$subcats);
1.28 raeburn 641: }
1.7 raeburn 642: if (keys(%courses) == 0) {
1.57 raeburn 643: if ($env{'form.currcat_0'} eq 'communities::0') {
644: $output = &mt('No communities match the criteria you selected.');
645: } else {
646: $output = &mt('No courses match the criteria you selected.');
647: }
1.7 raeburn 648: return $output;
649: }
1.32 raeburn 650: if (($knownuser) && (!$env{'form.showdetails'}) && (!&user_is_dc($domain))) {
1.31 bisitz 651: $output = '<b>'.&mt('Note for students:').'</b> '
652: .&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.')
653: .'<br /><br />';
1.8 raeburn 654: }
1.7 raeburn 655: }
1.27 raeburn 656: my $now = time;
657: my %domconfig =
658: &Apache::lonnet::get_dom('configuration',['usercreation'],$domain);
1.35 raeburn 659: $output .= &construct_data_table($knownuser,\%courses,$details,undef,$now,\%domconfig,$trails,$allitems);
1.41 raeburn 660: $output .= "\n".'<form name="linklaunch" method="post" action="">'.
1.40 raeburn 661: '<input type="hidden" name="backto" value="coursecatalog" />'.
1.41 raeburn 662: '<input type="hidden" name="courseid" value="" />'.
663: &Apache::lonhtmlcommon::echo_form_input(['catalogfilter','courseid']).'</form>';
1.15 raeburn 664: return $output;
665: }
666:
667: sub construct_data_table {
1.35 raeburn 668: my ($knownuser,$courses,$details,$usersections,$now,$domconfig,$trails,
669: $allitems) = @_;
1.7 raeburn 670: my %sortname;
1.16 raeburn 671: if (($details eq '') || ($env{'form.showdetails'})) {
1.7 raeburn 672: $sortname{'Code'} = 'code';
1.35 raeburn 673: $sortname{'Categories'} = 'cats';
1.7 raeburn 674: $sortname{'Title'} = 'title';
1.22 raeburn 675: $sortname{'Owner(s)'} = 'owner';
1.7 raeburn 676: }
1.15 raeburn 677: my $output = &Apache::loncommon::start_data_table().
678: &Apache::loncommon::start_data_table_header_row();
1.35 raeburn 679: my @coltitles = ('Count');
680: if ($env{'form.currcat_0'} eq 'instcode::0') {
681: push(@coltitles,'Code');
682: } else {
683: push(@coltitles,'Categories');
684: }
685: push(@coltitles,('Sections','Crosslisted','Title','Owner(s)'));
1.15 raeburn 686: if (ref($usersections) eq 'HASH') {
687: $coltitles[1] = 'Your Section';
688: }
1.7 raeburn 689: foreach my $item (@coltitles) {
690: $output .= '<th>';
691: if (defined($sortname{$item})) {
692: $output .= '<a href="javascript:changeSort('."'$sortname{$item}'".')">'.&mt($item).'</a>';
1.24 raeburn 693: } elsif ($item eq 'Count') {
694: $output .= ' ';
1.7 raeburn 695: } else {
696: $output .= &mt($item);
697: }
698: $output .= '</th>';
1.1 raeburn 699: }
1.15 raeburn 700: if ($knownuser) {
701: if ($details) {
1.8 raeburn 702: $output .=
1.7 raeburn 703: '<th>'.&mt('Default Access Dates for Students').'</th>'.
704: '<th>'.&mt('Student Counts').'</th>'.
1.42 bisitz 705: '<th>'.&mt('Auto-enrollment of[_1]registered students','<br />').'</th>';
1.15 raeburn 706: } else {
1.27 raeburn 707: $output .= '<th>'.&mt('Details').'</th>';
1.8 raeburn 708: }
1.1 raeburn 709: }
1.27 raeburn 710: $output .= '<th>'.&mt('Self-enroll (if permitted)').'</th>';
1.7 raeburn 711: &Apache::loncommon::end_data_table_header_row();
1.15 raeburn 712: my %courseinfo = &build_courseinfo_hash($courses,$knownuser,$details,
713: $usersections);
1.7 raeburn 714: my %Sortby;
1.15 raeburn 715: foreach my $course (sort(keys(%{$courses}))) {
1.7 raeburn 716: if ($env{'form.sortby'} eq 'code') {
717: push(@{$Sortby{$courseinfo{$course}{'code'}}},$course);
1.35 raeburn 718: } elsif ($env{'form.sortby'} eq 'cats') {
719: push(@{$Sortby{$courseinfo{$course}{'categories'}}},$course);
1.7 raeburn 720: } elsif ($env{'form.sortby'} eq 'owner') {
1.22 raeburn 721: push(@{$Sortby{$courseinfo{$course}{'ownerlastnames'}}},$course);
1.7 raeburn 722: } else {
1.25 raeburn 723: my $clean_title = $courseinfo{$course}{'title'};
724: $clean_title =~ s/\W+//g;
725: if ($clean_title eq '') {
726: $clean_title = $courseinfo{$course}{'title'};
727: }
728: push(@{$Sortby{$clean_title}},$course);
1.7 raeburn 729: }
730: }
731: my @sorted_courses;
1.35 raeburn 732: if (($env{'form.sortby'} eq 'code') || ($env{'form.sortby'} eq 'owner') ||
733: ($env{'form.sortby'} eq 'cats')) {
1.7 raeburn 734: @sorted_courses = sort(keys(%Sortby));
1.6 raeburn 735: } else {
1.7 raeburn 736: @sorted_courses = sort { lc($a) cmp lc($b) } (keys(%Sortby));
1.1 raeburn 737: }
1.24 raeburn 738: my $count = 1;
1.7 raeburn 739: foreach my $item (@sorted_courses) {
740: foreach my $course (@{$Sortby{$item}}) {
741: $output.=&Apache::loncommon::start_data_table_row();
1.35 raeburn 742: $output.=&courseinfo_row($courseinfo{$course},$knownuser,$details,
743: \$count,$now,$course,$trails,$allitems);
1.7 raeburn 744: $output.=&Apache::loncommon::end_data_table_row();
745: }
1.1 raeburn 746: }
1.7 raeburn 747: $output .= &Apache::loncommon::end_data_table();
748: return $output;
749: }
750:
751: sub build_courseinfo_hash {
1.15 raeburn 752: my ($courses,$knownuser,$details,$usersections) = @_;
1.1 raeburn 753: my %courseinfo;
1.7 raeburn 754: my $now = time;
1.15 raeburn 755: foreach my $course (keys(%{$courses})) {
1.1 raeburn 756: my $descr;
1.22 raeburn 757: if (ref($courses->{$course}) eq 'HASH') {
758: $descr = $courses->{$course}{'description'};
1.1 raeburn 759: }
760: my $cleandesc=&HTML::Entities::encode($descr,'<>&"');
761: $cleandesc=~s/'/\\'/g;
1.10 raeburn 762: $cleandesc =~ s/^\s+//;
1.1 raeburn 763: my ($cdom,$cnum)=split(/\_/,$course);
1.39 raeburn 764: my ($instcode,$singleowner,$ttype,$selfenroll_types,
1.35 raeburn 765: $selfenroll_start,$selfenroll_end,@owners,%ownernames,$categories);
1.22 raeburn 766: if (ref($courses->{$course}) eq 'HASH') {
767: $descr = $courses->{$course}{'description'};
1.23 raeburn 768: $instcode = $courses->{$course}{'inst_code'};
1.22 raeburn 769: $singleowner = $courses->{$course}{'owner'};
770: $ttype = $courses->{$course}{'type'};
1.27 raeburn 771: $selfenroll_types = $courses->{$course}{'selfenroll_types'};
772: $selfenroll_start = $courses->{$course}{'selfenroll_start_date'};
773: $selfenroll_end = $courses->{$course}{'selfenroll_end_date'};
1.35 raeburn 774: $categories = $courses->{$course}{'categories'};
1.22 raeburn 775: push(@owners,$singleowner);
776: if (ref($courses->{$course}{'co-owners'}) eq 'ARRAY') {
777: foreach my $item (@{$courses->{$course}{'co-owners'}}) {
778: push(@owners,$item);
779: }
780: }
781: }
782: foreach my $owner (@owners) {
1.54 raeburn 783: my ($ownername,$ownerdom);
1.22 raeburn 784: if ($owner =~ /:/) {
785: ($ownername,$ownerdom) = split(/:/,$owner);
786: } else {
787: $ownername = $owner;
788: if ($owner ne '') {
789: $ownerdom = $cdom;
790: }
791: }
792: if ($ownername ne '' && $ownerdom ne '') {
793: my %namehash=&Apache::loncommon::getnames($ownername,$ownerdom);
794: $ownernames{$ownername.':'.$ownerdom} = \%namehash;
1.1 raeburn 795: }
796: }
797: $courseinfo{$course}{'cdom'} = $cdom;
798: $courseinfo{$course}{'cnum'} = $cnum;
799: $courseinfo{$course}{'code'} = $instcode;
1.22 raeburn 800: my @lastnames;
801: foreach my $owner (keys(%ownernames)) {
802: if (ref($ownernames{$owner}) eq 'HASH') {
803: push(@lastnames,$ownernames{$owner}{'lastname'});
804: }
805: }
806: $courseinfo{$course}{'ownerlastnames'} = join(', ',sort(@lastnames));
1.1 raeburn 807: $courseinfo{$course}{'title'} = $cleandesc;
1.22 raeburn 808: $courseinfo{$course}{'owner'} = $singleowner;
1.27 raeburn 809: $courseinfo{$course}{'selfenroll_types'} = $selfenroll_types;
810: $courseinfo{$course}{'selfenroll_start'} = $selfenroll_start;
811: $courseinfo{$course}{'selfenroll_end'} = $selfenroll_end;
1.35 raeburn 812: $courseinfo{$course}{'categories'} = $categories;
1.7 raeburn 813:
814: my %coursehash = &Apache::lonnet::dump('environment',$cdom,$cnum);
815: my @classids;
816: my @crosslistings;
1.15 raeburn 817: my ($seclist,$numsec) =
818: &identify_sections($coursehash{'internal.sectionnums'});
819: if (ref($usersections) eq 'HASH') {
820: if (ref($usersections->{$course}) eq 'ARRAY') {
821: $seclist = join(', ',@{$usersections->{$course}});
822: }
823: }
1.7 raeburn 824: $courseinfo{$course}{'seclist'} = $seclist;
1.15 raeburn 825: my ($xlist_items,$numxlist) =
826: &identify_sections($coursehash{'internal.crosslistings'});
1.7 raeburn 827: my $showsyllabus = 1; # default is to include a syllabus link
828: if (defined($coursehash{'showsyllabus'})) {
829: $showsyllabus = $coursehash{'showsyllabus'};
830: }
831: $courseinfo{$course}{'showsyllabus'} = $showsyllabus;
1.15 raeburn 832: if (((defined($env{'form.coursenum'}) && ($cnum eq $env{'form.coursenum'}))) ||
1.22 raeburn 833: ($knownuser && ($details == 1))) {
1.15 raeburn 834: $courseinfo{$course}{'counts'} = &count_students($cdom,$cnum,$numsec);
835: $courseinfo{$course}{'autoenrollment'} =
836: &autoenroll_info(\%coursehash,$now,$seclist,$xlist_items,
1.22 raeburn 837: $instcode,\@owners,$cdom,$cnum);
1.15 raeburn 838:
839: my $startaccess = '';
840: my $endaccess = '';
841: my $accessdates;
842: if ( defined($coursehash{'default_enrollment_start_date'}) ) {
843: $startaccess = &Apache::lonlocal::locallocaltime($coursehash{'default_enrollment_start_date'});
844: }
845: if ( defined($coursehash{'default_enrollment_end_date'}) ) {
846: $endaccess = &Apache::lonlocal::locallocaltime($coursehash{'default_enrollment_end_date'});
847: if ($coursehash{'default_enrollment_end_date'} == 0) {
1.34 raeburn 848: $endaccess = &mt('No ending date');
1.15 raeburn 849: }
850: }
851: if ($startaccess) {
1.42 bisitz 852: $accessdates .= '<i>'.&mt('From:[_1]','</i> '.$startaccess).'<br />';
1.7 raeburn 853: }
1.15 raeburn 854: if ($endaccess) {
1.42 bisitz 855: $accessdates .= '<i>'.&mt('To:[_1]','</i> '.$endaccess).'<br />';
1.15 raeburn 856: }
1.34 raeburn 857: if (($selfenroll_types ne '') &&
858: ($selfenroll_end > 0 && $selfenroll_end > $now)) {
859: my ($selfenroll_start_access,$selfenroll_end_access);
860: if (($coursehash{'default_enrollment_start_date'} ne
861: $coursehash{'internal.selfenroll_start_access'}) ||
862: ($coursehash{'default_enrollment_end_date'} ne
863: $coursehash{'internal.selfenroll_end_access'})) {
864: if ( defined($coursehash{'internal.selfenroll_start_access'}) ) {
865: $selfenroll_start_access = &Apache::lonlocal::locallocaltime($coursehash{'internal.selfenroll_start_access'});
866: }
867: if ( defined($coursehash{'default_enrollment_end_date'}) ) {
868: $selfenroll_end_access = &Apache::lonlocal::locallocaltime($coursehash{'internal.selfenroll_end_access'});
869: if ($coursehash{'internal.selfenroll_end_access'} == 0) {
870: $selfenroll_end_access = &mt('No ending date');
871: }
872: }
873: if ($selfenroll_start_access || $selfenroll_end_access) {
874: $accessdates .= '<br/><br /><i>'.&mt('Self-enrollers:').'</i><br />';
875: if ($selfenroll_start_access) {
1.42 bisitz 876: $accessdates .= '<i>'.&mt('From:[_1]','</i> '.$selfenroll_start_access).'<br />';
1.34 raeburn 877: }
878: if ($selfenroll_end_access) {
1.42 bisitz 879: $accessdates .= '<i>'.&mt('To:[_1]','</i> '.$selfenroll_end_access).'<br />';
1.34 raeburn 880: }
881: }
882: }
883: }
1.15 raeburn 884: $courseinfo{$course}{'access'} = $accessdates;
1.1 raeburn 885: }
1.7 raeburn 886: if ($xlist_items eq '') {
887: $xlist_items = &mt('No');
1.1 raeburn 888: }
1.7 raeburn 889: $courseinfo{$course}{'xlist'} = $xlist_items;
1.1 raeburn 890: }
1.7 raeburn 891: return %courseinfo;
1.1 raeburn 892: }
893:
1.7 raeburn 894: sub count_students {
1.15 raeburn 895: my ($cdom,$cnum,$numsec) = @_;
1.1 raeburn 896: my $classlist = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.7 raeburn 897: my %student_count = (
898: Active => 0,
899: Future => 0,
900: Expired => 0,
901: );
1.1 raeburn 902: my %idx;
903: $idx{'status'} = &Apache::loncoursedata::CL_STATUS();
1.4 albertel 904: my %status_title = &Apache::lonlocal::texthash(
1.1 raeburn 905: Expired => 'Previous access',
906: Active => 'Current access',
907: Future => 'Future access',
908: );
1.7 raeburn 909:
1.4 albertel 910: while (my ($student,$data) = each(%$classlist)) {
1.1 raeburn 911: $student_count{$data->[$idx{'status'}]} ++;
912: }
1.7 raeburn 913:
1.43 bisitz 914: my $countslist = &mt('[quant,_1,section:,sections:,No sections]',$numsec).'<br />';
1.7 raeburn 915: foreach my $status ('Active','Future') {
1.43 bisitz 916: $countslist .= '<span class="LC_nobreak">'.$status_title{$status}.': '.
917: $student_count{$status}.'</span><br />';
1.1 raeburn 918: }
1.7 raeburn 919: return $countslist;
920: }
921:
922: sub courseinfo_row {
1.35 raeburn 923: my ($info,$knownuser,$details,$countref,$now,$course,$trails,$allitems) = @_;
1.7 raeburn 924: my ($cdom,$cnum,$title,$ownerlast,$code,$owner,$seclist,$xlist_items,
1.35 raeburn 925: $accessdates,$showsyllabus,$counts,$autoenrollment,$output,$categories);
1.7 raeburn 926: if (ref($info) eq 'HASH') {
927: $cdom = $info->{'cdom'};
928: $cnum = $info->{'cnum'};
929: $title = $info->{'title'};
1.22 raeburn 930: $ownerlast = $info->{'ownerlastnames'};
1.7 raeburn 931: $code = $info->{'code'};
932: $owner = $info->{'owner'};
933: $seclist = $info->{'seclist'};
934: $xlist_items = $info->{'xlist'};
935: $accessdates = $info->{'access'};
936: $counts = $info->{'counts'};
937: $autoenrollment = $info->{'autoenrollment'};
938: $showsyllabus = $info->{'showsyllabus'};
1.35 raeburn 939: $categories = $info->{'categories'};
1.7 raeburn 940: } else {
941: $output = '<td colspan="8">'.&mt('No information available for [_1].',
942: $code).'</td>';
943: return $output;
1.2 raeburn 944: }
1.35 raeburn 945: $output .= '<td>'.$$countref.'</td>';
946: if ($env{'form.currcat_0'} eq 'instcode::0') {
947: $output .= '<td>'.$code.'</td>';
948: } else {
949: my ($categorylist,@cats);
950: if ($categories ne '') {
951: @cats = split('&',$categories);
952: }
953: if ((ref($trails) eq 'ARRAY') && (ref($allitems) eq 'HASH')) {
954: my @categories = map { $trails->[$allitems->{$_}]; } @cats;
955: $categorylist = join('<br />',@categories);
956: }
957: if ($categorylist eq '') {
958: $categorylist = ' ';
959: }
960: $output .= '<td>'.$categorylist.'</td>';
961: }
962: $output .= '<td>'.$seclist.'</td>'.
1.7 raeburn 963: '<td>'.$xlist_items.'</td>'.
964: '<td>'.$title.' <font size="-2">';
1.2 raeburn 965: if ($showsyllabus) {
1.40 raeburn 966: $output .= '<a href="javascript:ToSyllabus('."'$cdom','$cnum'".')">'.&mt('Syllabus').'</a>';
1.7 raeburn 967: } else {
968: $output .= ' ';
1.2 raeburn 969: }
970: $output .= '</font></td>'.
1.7 raeburn 971: '<td>'.$ownerlast.'</td>';
1.15 raeburn 972: if ($knownuser) {
973: if ($details) {
1.8 raeburn 974: $output .=
1.7 raeburn 975: '<td>'.$accessdates.'</td>'.
976: '<td>'.$counts.'</td>'.
977: '<td>'.$autoenrollment.'</td>';
1.15 raeburn 978: } else {
979: $output .= "<td><a href=\"javascript:setCourseId('$cnum')\">".&mt('Show more details').'</a></td>';
1.8 raeburn 980: }
1.7 raeburn 981: }
1.27 raeburn 982: my $selfenroll;
983: if ($info->{'selfenroll_types'}) {
984: my $showstart = &Apache::lonlocal::locallocaltime($info->{'selfenroll_start'});
985: my $showend = &Apache::lonlocal::locallocaltime($info->{'selfenroll_end'});
986: if (($info->{'selfenroll_end'} > 0) && ($info->{'selfenroll_end'} > $now)) {
987: if (($info->{'selfenroll_start'} > 0) && ($info->{'selfenroll_start'} > $now)) {
988: $output .= '<td>'.&mt('Starts: [_1]','<span class="LC_cusr_emph">'.$showstart.'</span>').'<br />'.&mt('Ends: [_1]','<span class="LC_cusr_emph">'.$showend.'</span>').'</td>';
989: } else {
1.41 raeburn 990: $output .= '<td><a href="javascript:ToSelfenroll('."'$course'".')">'.&mt('Enroll in course').'</a></td>';
1.27 raeburn 991: }
992: $selfenroll = 1;
993: }
994: }
995: if (!$selfenroll) {
996: $output .= '<td> </td>';
997: }
1.24 raeburn 998: $$countref ++;
1.1 raeburn 999: return $output;
1000: }
1001:
1002: sub identify_sections {
1003: my ($seclist) = @_;
1004: my @secnums;
1005: if ($seclist =~ /,/) {
1.4 albertel 1006: my @sections = split(/,/,$seclist);
1.1 raeburn 1007: foreach my $sec (@sections) {
1008: $sec =~ s/:[^:]*$//;
1009: push(@secnums,$sec);
1010: }
1011: } else {
1012: if ($seclist =~ m/^([^:]+):/) {
1013: my $sec = $1;
1.4 albertel 1014: if (!grep(/^\Q$sec\E$/,@secnums)) {
1015: push(@secnums,$sec);
1.1 raeburn 1016: }
1017: }
1018: }
1019: @secnums = sort {$a <=> $b} @secnums;
1.39 raeburn 1020: $seclist = join(', ',@secnums);
1.15 raeburn 1021: my $numsec = @secnums;
1022: return ($seclist,$numsec);
1.1 raeburn 1023: }
1024:
1.2 raeburn 1025: sub get_valid_classes {
1.22 raeburn 1026: my ($seclist,$xlist_items,$crscode,$owners,$cdom,$cnum) = @_;
1.2 raeburn 1027: my $response;
1028: my %validations;
1029: @{$validations{'sections'}} = ();
1030: @{$validations{'xlists'}} = ();
1031: my $totalitems = 0;
1032: if ($seclist) {
1.13 raeburn 1033: foreach my $sec (split(/, /,$seclist)) {
1.2 raeburn 1034: my $class = $crscode.$sec;
1.22 raeburn 1035: if (&Apache::lonnet::auto_validate_class_sec($cdom,$cnum,$owners,
1.3 albertel 1036: $class) eq 'ok') {
1.2 raeburn 1037: if (!grep(/^\Q$sec$\E/,@{$validations{'sections'}})) {
1.4 albertel 1038: push(@{$validations{'sections'}},$sec);
1.2 raeburn 1039: $totalitems ++;
1040: }
1041: }
1042: }
1043: }
1044: if ($xlist_items) {
1.13 raeburn 1045: foreach my $item (split(/, /,$xlist_items)) {
1.22 raeburn 1046: if (&Apache::lonnet::auto_validate_class_sec($cdom,$cnum,$owners,
1.3 albertel 1047: $item) eq 'ok') {
1.2 raeburn 1048: if (!grep(/^\Q$item$\E/,@{$validations{'xlists'}})) {
1.4 albertel 1049: push(@{$validations{'xlists'}},$item);
1.2 raeburn 1050: $totalitems ++;
1051: }
1052: }
1053: }
1054: }
1055: if ($totalitems > 0) {
1056: if (@{$validations{'sections'}}) {
1.42 bisitz 1057: $response = &mt('Sections:').' '.
1.14 raeburn 1058: join(', ',@{$validations{'sections'}}).'<br />';
1.2 raeburn 1059: }
1060: if (@{$validations{'xlists'}}) {
1.42 bisitz 1061: $response .= &mt('Courses:').' '.
1.14 raeburn 1062: join(', ',@{$validations{'xlists'}});
1.2 raeburn 1063: }
1064: }
1065: return $response;
1066: }
1067:
1.7 raeburn 1068: sub autoenroll_info {
1.22 raeburn 1069: my ($coursehash,$now,$seclist,$xlist_items,$code,$owners,$cdom,$cnum) = @_;
1.7 raeburn 1070: my $autoenrolldates = &mt('Not enabled');
1071: if (defined($coursehash->{'internal.autoadds'}) && $coursehash->{'internal.autoadds'} == 1) {
1072: my ($autostart,$autoend);
1073: if ( defined($coursehash->{'internal.autostart'}) ) {
1074: $autostart = &Apache::lonlocal::locallocaltime($coursehash->{'internal.autostart'});
1075: }
1076: if ( defined($coursehash->{'internal.autoend'}) ) {
1077: $autoend = &Apache::lonlocal::locallocaltime($coursehash->{'internal.autoend'});
1078: }
1079: if ($coursehash->{'internal.autostart'} > $now) {
1080: if ($coursehash->{'internal.autoend'} && $coursehash->{'internal.autoend'} < $now) {
1081: $autoenrolldates = &mt('Not enabled');
1082: } else {
1083: my $valid_classes =
1084: &get_valid_classes($seclist,$xlist_items,$code,
1.22 raeburn 1085: $owners,$cdom,$cnum);
1.7 raeburn 1086: if ($valid_classes ne '') {
1.42 bisitz 1087: $autoenrolldates = &mt('Not enabled').'<br />'
1088: .&mt('Starts: [_1]',$autostart)
1089: .'<br />'.$valid_classes;
1090: }
1.7 raeburn 1091: }
1092: } else {
1093: if ($coursehash->{'internal.autoend'} && $coursehash->{'internal.autoend'} < $now) {
1.42 bisitz 1094: $autoenrolldates = &mt('Not enabled').'<br />'
1095: .&mt('Ended: [_1]',$autoend);
1.7 raeburn 1096: } else {
1097: my $valid_classes = &get_valid_classes($seclist,$xlist_items,
1.22 raeburn 1098: $code,$owners,$cdom,$cnum);
1.7 raeburn 1099: if ($valid_classes ne '') {
1.42 bisitz 1100: $autoenrolldates = &mt('Currently enabled').'<br />'.
1.7 raeburn 1101: $valid_classes;
1102: }
1103: }
1104: }
1105: }
1106: return $autoenrolldates;
1107: }
1108:
1.8 raeburn 1109: sub user_is_known {
1110: my $known = 0;
1111: if ($env{'user.name'} ne '' && $env{'user.name'} ne 'public'
1112: && $env{'user.domain'} ne '' && $env{'user.domain'} ne 'public') {
1113: $known = 1;
1114: }
1115: return $known;
1116: }
1117:
1.1 raeburn 1118: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>