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