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