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