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