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