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