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