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