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