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