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